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
Problem With Simple SendMail Script
Moderator: General Moderators
-
costamesakid
- Forum Newbie
- Posts: 1
- Joined: Tue Jan 12, 2010 12:43 am
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Problem With Simple SendMail Script
Regarding your second question :
This should place it in the order you desire.
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);
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering