Results 1 to 5 of 5

Thread: sendmail form

  1. #1
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default sendmail form

    Hi all,

    Any ideas on this one? I have a php mail form that posts info from the web browser to my email account.

    Problem is, when I receive the email I only get half the message from the web form.

    I receive info only form,

    Selected turf required:
    Area to apply turf
    Soil required:
    Delivery required:

    Any help and suggestions greatly appreciated thanks.

    I must be missing somthing I'm not seeing.

    here is my code:

    Code:
    <?php
    
    // process the email
    if (array_key_exists('submit', $_POST)) {
      ini_set("sendmail_from", "your email");
    
    $to = 'your email';
    $subject = 'your subject';
    // send email 
    $message =  'Selected turf required: ' . $_REQUEST['turfselectbox'] . "\n\n" . 
    			'Area to apply turf: ' . $_REQUEST['turfarea'] . "\n\n" . 
    			'Soil required: ' . $_REQUEST['radioturf'] . "\n\n" . 
    			'Delivery required: ' . $_REQUEST['radiodel']; "\n\n" . 
    			'Service required: ' . $_REQUEST['serviceselectbox']; "\n\n" . 
    			'Name/Business: ' . $_REQUEST['name']; "\n\n" . 
    			'Postal address: ' . $_REQUEST['postaddress']; "\n\n" . 
    			'Post code: ' . $_REQUEST['pcode']; "\n\n" . 
    			'Telephone no.: ' . $_REQUEST['tel']; "\n\n" . 
    			'Email address: ' . $_REQUEST['email']; "\n\n" . 
    			'Message: ' . $_REQUEST['notes']; "\n\n" .
    
    $email = $_REQUEST['email'];
    $headers = 'From: ' . $email . "\r\n" .
    'Reply-To: ' . $email . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    
    mail ($to, $subject, $message, $headers, "your email");
      
      // list expected fields
      $expected = array('turfselectbox', 'turfarea', 'radioturf', 'radiodel', 'serviceselectbox', 'name', 'postaddress', 'pcode', 'tel', 'email', 'notes');
      // set required fields
      $required = array('turfselectbox', 'serviceselectbox', 'name', 'postaddress', 'pcode', 'tel', 'email');
      // create empty array for any missing fields
      $missing = array();
      
      // process the $_POST variables
      foreach ($_POST as $key => $value) {
        // assign to temporary variable and strip whitespace if not an array
        $temp = is_array($value) ? $value : trim($value);
    	// if empty and required, add to $missing array
    	if (empty($temp) && in_array($key, $required)) {
    	  array_push($missing, $key);
    	  }
    	// otherwise, assign to a variable of the same name as $key
    	elseif (in_array($key, $expected)) {
    	  ${$key} = $temp;
    	  }
    	}
    
    	// validate the email address
    	if (!empty($email)) {
    
    	// regex to ensure no illegal characters in email address
    	$checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
    
    	// reject the email address if it doesn't match
    	if (!preg_match($checkEmail, $email)) {
    	array_push($missing, 'email');
    	}
    	}
     
      // go ahead only if all required fields OK
      if (empty($missing)) {
        // build the message
        $message = "Selected turf required: $turfselectbox\n\n";
        $message .= "Area to apply turf: $turfarea\n\n";
    	$message .= "Soil required: $radioturf\n\n";
    	$message .= "Delivery required: $radiodel\n\n";
        $message .= "Service required: $serviceselectbox\n\n";
        $message .= "Name/Business: $name\n\n";
    	$message .= "Postal address: $postaddress\n\n";
    	$message .= "Post code: $pcode\n\n";
    	$message .= "Telephone no.: $tel\n\n";
    	$message .= "Email address: $email\n\n";
    	$message .= "Message: $notes\n\n";
    
        // limit line length to 70 characters
        $message = wordwrap($message, 200);
      
        // send it  
        $sendmail_from = mail($to, $subject, $message);
    	if ($sendmail_from) {
    	  // $missing is no longer needed if the email is sent, so unset it
    	  unset($missing);
    	  }
        }
      }
    ?>
        <?php
    		if ($_POST && isset($missing)) {
    ?>
        <p class="main_warning">Please complete the missing item(s) indicated. Your message has not been sent.</p>
        <?php
    		  }
    		elseif ($_POST && !$sendmail_from) {
    ?>
        <p class="main_warning">Sorry, there was a problem sending your message. Please try later.</p>
        <?php
    		  }
    		elseif ($_POST && $sendmail_from) {
    ?>
        <span class="confmsg"><h2>Thank you for your quotation request. We will reply to you as soon as possible.</h2></span>
    
    <?php } ?>
    
    <form id="quoteform" name="contactform" method="post" action="">
    <p>(<font color="#FF0000">*</font>) Are mandatory fields.</p>
          <?php
    	if (isset($missing) && in_array('turfselectbox', $missing)) { ?>
          <span class="warning">Enter turf if required.</span>
          <?php } ?>
    
    <label><abbr title="Select turf required."><font color="#FF0000"><sup>*</sup></font>Select turf required:</abbr>
    
    <select name="turfselectbox" id="turfselectbox" size="1">
    <option selected="selected">Please Select</option>
    <option>Meadow Lawn Turf</option>
    <option>Premium Turf</option>
    <option>None</option>
    </select>
    </label>
    
    <label>
    <abbr title="Area to apply turf:">Area to apply turf:</abbr>
    <input type="text" name="turfarea" id="turfarea" maxlength="40"/> M<sup>2</sup>
    <a href="javascript:popUp('turf_calculator.php')"><img src="img/calculator.jpg" width="16" height="16" title="Turf Calculator" alt="Turf Calculator" /></a></label>
    
    
    <label><abbr title="Do you require soil?">Do you require soil?</abbr></label>
    
    <label><input id="radiosoil" name="radioturf" type="radio" value="Yes" checked="checked"></input>Yes</label>
    
    <label><input id="radiosoilb" name="radioturf" type="radio" value="No"></input>No</label>
    
    <label><abbr title="Do you require delivery?">Do you require delivery?</abbr></label>
    
    <label><input id="radiodel" name="radiodel" type="radio" value="Yes" checked="checked"></input>Yes</label>
    
    <label><input id="radiodelb" name="radiodel" type="radio" value="No"></input>No</label>
    
          <?php
    	if (isset($missing) && in_array('serviceselectbox', $missing)) { ?>
          <span class="warning">Enter the type of service you require.</span>
          <?php } ?>
    
    <label>
    
    <abbr title="What type of service do you require?"><font color="#FF0000"><sup>*</sup></font>What service do you require?</abbr>
    
    <select name="serviceselectbox" id="serviceselectbox" size="1">
    <option selected="selected">Please select</option>
    <option>Turf supplied to order</option>
    <option>Lawn preparation and turf laying</option>
    <option>Stonewalling</option>
    <option>Brick-paved driveways</option>
    <option>Hedge laying</option>
    <option>Garden planning</option>
    <option>Garden sheds and benches</option>
    <option>Timber fences</option>
    <option>Rockery creation</option>
    <option>Water features and ponds</option>
    <option>Raised decking</option>
    <option>Grass seeding and plant selections</option>
    <option>Garden clearances</option>
    <option>Retaining wall systems</option>
    <option>None</option>
    </select>
    
    </label>
    
          <?php
    	if (isset($missing) && in_array('name', $missing)) { ?>
          <span class="warning">Enter your name.</span>
          <?php } ?>
    
    <label><abbr title="Enter your name."><font color="#FF0000"><sup>*</sup></font>Name/Business:</abbr>
    
    <input type="text" name="name" id="name" maxlength="35" /></label>
    
          <?php
    	if (isset($missing) && in_array('postaddress', $missing)) { ?>
          <span class="warning">Enter your postal address.</span>
          <?php } ?>
    
    <label><abbr title="Enter your postal address."><font color="#FF0000"><sup>*</sup></font>Postal address:</abbr></label>
    
    <textarea name="postaddress" id="postaddress" cols="0" rows="7"></textarea>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <?php
    	if (isset($missing) && in_array('pcode', $missing)) { ?>
          <span class="warning">Enter your postal code.</span>
          <?php } ?>
    
    <label>
    <abbr title="Enter your post code."><font color="#FF0000"><sup>*</sup></font>Post code:</abbr> 
    <input type="text" name="pcode" id="pcode" maxlength="25" /></label>
    
          <?php
    	if (isset($missing) && in_array('tel', $missing)) { ?>
          <span class="warning">Enter your contact telephone no.</span>
          <?php } ?>
    
    <label>
    <abbr title="Enter your contact telephone no."><font color="#FF0000"><sup>*</sup></font>Telephone no.:</abbr> 
    <input type="text" name="tel" id="tel" maxlength="25" /></label>
    
          <?php
    	if (isset($missing) && in_array('email', $missing)) { ?>
          <span class="warning">Enter your email address.</span>
          <?php } ?>
    
    <label>
    <abbr title="Enter your email address."><font color="#FF0000"><sup>*</sup></font>Email address:</abbr>
    
    <input type="text" name="email" id="email" maxlength="25" /></label>
    
    <label><abbr title="Enter your message.">Message:</abbr></label>
    
    <textarea name="notes" id="notes" cols="0" rows="7"></textarea>
    
    <input type="submit" name="submit" id="submit" class="submit" value="Request Quotation" title="Request Quotation" />
    
    <input type="reset" name="reset" id="reset" class="reset" value="Reset" title="Reset" />
    
    </form>
    Last edited by john0611; 08-11-2009 at 08:24 AM.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    The only difference I can see is that in the first 3 lines of $message you terminate the variable portion with a ".", eg 'Area to apply turf: ' . $_REQUEST['turfarea'] ., the fourth line is terminated by a ";", eg 'Delivery required: ' . $_REQUEST['radiodel'];.

    Try replacing the ";" with "."

  3. The Following User Says Thank You to forum_amnesiac For This Useful Post:

    john0611 (08-11-2009)

  4. #3
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Yep, I'll agree with amnesiac. ";" ends your string.

    If you don't get sent info (Selected turf: blah blah blah), you might have problem with $_REQUEST['turfselectbox'].
    Sorry can't look at your code a lot now. At school right now :P

  5. The Following User Says Thank You to allahverdi For This Useful Post:

    john0611 (08-11-2009)

  6. #4
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    It Works, Fantastic! Thanks for pointing that out.

  7. #5
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help all, easy how you look at things all day and it just dosent click in lol

    thanks all.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •