+ Reply to Thread
Results 1 to 5 of 5

Thread: I need some php scripting help for a web form

  1. #1
    djrobuk is offline x10Hosting Member djrobuk is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    I need some php scripting help for a web form

    I have a php script on my website to handle a form on a webpage, but I'm a bit clueless when it comes to php scripting. I have entered my email address in the php script (this address is what the form will be sent to). When I trial the form and submit, it says successfully sent but I don't recieve any emails. I understand that the web space host needs to be able to accept php to do this, which it is. I'm not sure how a host is able to handle a request to send an email though.

    My script is as follows:

    <?php

    $my_email = "MY EMAIL ADDRESS IS PLACED HERE";

    $continue = "MY WEB ADDRESS HERE";

    $errors = array();

    // Remove $_COOKIE elements from $_REQUEST.

    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

    // Check all fields for an email header.

    function recursive_array_check_header($element_value)
    {

    global $set;

    if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
    else
    {

    foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}

    }

    }

    recursive_array_check_header($_REQUEST);

    if($set){$errors[] = "You cannot send an email header";}

    unset($set);

    // Validate email field.

    if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
    {

    if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}

    $_REQUEST['email'] = trim($_REQUEST['email']);

    if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

    }

    // Check referrer is from same site.

    if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

    // Check for a blank form.

    function recursive_array_check_blank($element_value)
    {

    global $set;

    if(!is_array($element_value)){if(!empty($element_v alue)){$set = 1;}}
    else
    {

    foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

    }

    }

    recursive_array_check_blank($_REQUEST);

    if(!$set){$errors[] = "You cannot send a blank form";}

    unset($set);

    // Display any errors and exit if errors exist.

    if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

    if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

    // Build message.

    function build_message($request_input){if(!isset($message_o utput)){$message_output ="";}if(!is_array($request_input)){$message_out put = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$ message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$mes sage_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

    $message = build_message($_REQUEST);

    $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."";

    $message = stripslashes($message);

    $subject = "FormToEmail Comments";

    $headers = "From: " . $_REQUEST['email'];

    mail($my_email,$subject,$message,$headers);

    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>

    <head>
    <title>Thank You - Your Message Has Been Sent</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#ffffff" text="#000000">

    <div>
    <center>
    <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
    <br>Your message has been sent
    <p><a href="<?php print $continue; ?>">Click here to continue</a></p>
    </center>
    </div>

    </body>
    </html>
    Last edited by djrobuk; 10-24-2009 at 11:22 AM.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: I need some php scripting help for a web form

    One thing you can try is make sure the variables contain what you want.
    Try testing:

    HTML Code:
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     
    <html>
     
    <head>
    <title>Thank You - Your Message Has Been Sent</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
     
    <body bgcolor="#ffffff" text="#000000">
     
    <div>
    <center>
    <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
    <br>Your message has been sent
    <p><a href="<?php print $continue; ?>">Click here to continue</a></p>
    </center>
    </div>
     
    DEBUG information: <br/>
    <?php echo "Variables: $my_email <br /> $subject <br /> $message <br /> $headers <br />" ; ?>
     
     
     
    </body>
    </html>
     
    Second, your ISP might consider the email spam, since the 'From' address might have no relationship to the true sender, your x10 account. If that is the case, you should make the 'From' address your x10 account and add the user's email address to the body of the message.
    Nothing is always absolutely so.

  3. #3
    djrobuk is offline x10Hosting Member djrobuk is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    Re: I need some php scripting help for a web form

    I have added the debug information to the code and also used my x10hosting email address but to no avail. For some reason I am still unable to receive the information in my web form.

    My HTML page where the web form is, is as follows:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <LINK REL="SHORTCUT ICON"
           HREF="favicon.ico">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>ROB'S MOBILE DISCO - AVAILABLE FOR HIRE IN NORTH EAST WALES &amp; SURROUNDING AREAS.</title>
    <link rel="stylesheet" type="text/css" href="styles.css"/>
    <style type="text/css">
    <!--
    .style1 {
     font-size: 18px;
     font-weight: bold;
    }
    -->
    </style>
    </head>
    <body>
    <div id="container" align="center">
    <div id="page" class="text" align="left">
    <div id="header"></div>
    <div id="links" align="center"><a href="index.html" onmouseover="window.status='Return to Homepage'; return true;" onmouseout="window.status=''; return true;">Home</a> <a href="quote.html" onmouseover="window.status='Get a quote online'; return true;" onmouseout="window.status=''; return true;">Quote</a> <a href="occasions.html" onmouseover="window.status='For information on occasions catered for and extras to make the occasion special'; return true;" onmouseout="window.status=''; return true;">Occasions</a> <a href="#" onmouseover="window.status='Click to sign or view the Guest Book'; return true;" onmouseout="window.status=''; return true;">Guest Book</a> <a href="music.html" onmouseover="window.status='For information on the music genres available and some examples'; return true;" onmouseout="window.status=''; return true;">Music</a> <a href="equipment.html" onmouseover="window.status='The equipment that I will use at your event'; return true;" onmouseout="window.status=''; return true;">Equipment</a> <a href="links.html" onmouseover="window.status='A selection of useful links can be found here'; return true;" onmouseout="window.status=''; return true;">Links</a></div>
    <div id="content">
      <h2>Quotation</h2>
      <h4>Please enter your details below and I will get back in touch with you as soon as possible with a no obligation quote. </h4>
      <form action="FormToEmail.php" method="post" name="contactform">  
          <label>Name:</label>
       <br />
       <input name="name" type="text" id="name" size="40" />
       <br />
       <br />
       <label>Address:<label>
       <br />
       <textarea name="" cols="40" rows="8"></textarea>
       <br />
       <label>Email Address:<label>
       <br />
       <input name="email" type="text" id="email" size="40" />
       <br />
       <label>Occasion:<label>
       <br />
       <input name="occasion" type="text" id="occasion" size="40" />
       <br />
       <label>Venue:<label>
       <br />
       <textarea name="venue" cols="40" rows="8" id="venue">Please enter address details of your chosen venue here... (If you are not yet sure of a venue then enter a rough location)</textarea>
       <br />
       <label>Start Time:<label>
       <br />
       <input name="start" type="text" id="start" value="Please enter in 24 hours (e.g. 14:00)" size="40" />
       <br />
       <label>End Time:<label>
       <br />
       <input name="end" type="text" id="end" value="Please enter in 24 hours (e.g. 14:00)" size="40" />
       <br />
       <br />
       <input name="recipient" type="hidden" id="recipient" value="EMAIL ADDRESS HERE" />
          <input type="submit" name="Submit" value="Submit" />
          <input type="reset" name="Reset" value="Reset" />
        </p>
      </form>
      <p class="style1">PLEASE DO NOT ENTER DETAILS JUST YET. WEB FORM STILL UNDER CONSTRUCTION </p>
      </div>
    <div id="clearfloats"></div>
    <div id="footer" align="left"><div id="footerT"><img src="images/footerT.jpg" alt="" width="349" height="256" border="0" /></div><div id="footerC"></div>
    </div>
    </div>
    </div>
    </body>
    </html>

  4. #4
    gratanas is offline x10Hosting Member gratanas is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    1

    Lightbulb Re: I need some php scripting help for a web form

    I recommend that you go here for better help http://www.w3schools.com/php/php_forms.asp :cool:

  5. #5
    djrobuk is offline x10Hosting Member djrobuk is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    Re: I need some php scripting help for a web form

    After hours of looking into it. Finally sorted it out I deleted the following attribute:

    HTML Code:
    $headers = "From: " . $_REQUEST['email'];
    It works fine now!

+ Reply to Thread

Similar Threads

  1. Upload problem with my php form... Please help!
    By uplinked in forum Free Hosting
    Replies: 6
    Last Post: 12-12-2008, 09:13 AM
  2. Javascript form to PHP
    By driveflexfuel in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 10-28-2008, 11:15 PM
  3. PHP contact form styling (line spacing)
    By xxll_martin_llxx in forum Programming Help
    Replies: 3
    Last Post: 07-24-2008, 10:09 AM
  4. Easy XHTML form validation using PHP
    By Xemnas in forum Tutorials
    Replies: 0
    Last Post: 01-08-2008, 04:29 AM
  5. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers