Page 1 of 1

Problem With Simple SendMail Script

Posted: Tue Jan 12, 2010 12:56 am
by costamesakid
I wrote a sendmail script 10 years ago that was easy and worked. Im having trouble on this one.

HERE IS THE FORM CONTAINING THE DATA I WANT TO EMAIL:

<form action="sendmail.php" method="POST" name="contact" onsubmit="return validate();">
<tr>
<td align="right">*Name: </td>
<td align="left"><input type="text" name="name" size="30" maxlength="30"></td>
</tr>
<tr>
<td align="right" >*Email: </td>
<td align="left"><input name="email" type="text" size="30" maxlength="30"></td> </tr>
<tr>
<td align="right" valign="top">Comments: </td>
<td align="left"><textarea name="comments" cols="25" rows="3" WRAP></textarea></td>
</tr>
<tr>
<td align="right" colspan="2"><input type="submit" value="Send" name="submit">
</tr>
</form>

HERE IS THE PHP SCRIPT:

<?php
$to = "kgroup@aol.com";
$subject = "Planning Group Web Inquiry";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$comments = $_REQUEST['comments'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $name, $comments, $headers);
if($sent)
header( "Location: http://www.planninggroup.com/thankyou.html" );
else
header( "Location: http://www.planninggroup.com/sorry.html" );
?>

HERE ARE THE ISSUES:

1. When I receive the email the From field is set to my webservers address instead of the email field of the form.
2. The contents of the email display the comments first, followed by name. I would like the comments to be displayed after the name.


Any help with matter is really appreciated. Thanks

Re: Problem With Simple SendMail Script

Posted: Tue Jan 12, 2010 6:16 am
by social_experiment
Regarding your second question :

Code: Select all

 
<?php
 
  $to = "kgroup@aol.com";
  $subject = "Planning Group Web Inquiry";
  $email = $_REQUEST['email'] ;
  $name = $_REQUEST['name'] ;
  $comments = $_REQUEST['comments'] ;
  $message = "
       $name    
       $comments
  ";
 
  $headers = "From: $email";
  $sent = mail($to, $subject, $message, $headers);
?>
 
This should place it in the order you desire.