PDA

View Full Version : PHP FROM: header in a form mail...


splace
02-11-2004, 02:49 AM
I am having some issues where I have a simple PHP form mail, which I will post up here, that works, however when I fill out the form and send it, everything goes through fine except it does not display the 'From' properly. It spits out 'nobody' in the from field. In adidtion, if i add the variable with the header declerations in it...$extra = "From: $Name\r\nReply-To: $Email\r\n"; for example, it will go through, but I will never recieve an email.

mail(blahblahblah,$extra);

This is what the mail would look like.

Thoughts?

PHP CODE


<?

//Contents of form in free_session.htm
$first_name=$_POST['First_Name'];
$last_name=$_POST['Last_Name'];
$phone_01=$_POST['Phone_01'];
$phone_02=$_POST['Phone_02'];
$phone_03=$_POST['Phone_03'];
$email=$_POST['Email'];
$goals=$_POST['Goals'];


$recipient = "steven.place@lucidapple.com";
$subject = "Free 45 Minuite Coaching Session Request";
$message = "Name: " . $first_name . " " . $last_name . "\n"
. "Phone: " . $phone_01 . "-" . $phone_02 . "-" . $phone_03 . "\n"
. "Email: " . $email . "\n"
. "Goals: " . $goals;
$from = "User requesting a free 45 minuite consultation. \n";


mail($recipient,$subject, $message, $from, $email);

header("Location: php/sent.php");

?>


-Steve

y6y6y6
02-11-2004, 09:07 AM
Your example code is all wrong. Should be more like:

$to = "mary@example.com";
$subject = "Birthday Reminders";
$message = 'Birthday Reminders for August';
$headers .= "From: Birthday <birthday@example.com>\r\n";

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

As for the other strategy, I think you need:

$extra = "From: $Name <$Email>\r\n";

splace
02-11-2004, 10:46 AM
Thats interesting, but my main problem is with the headers. I want to get it so that i can use headers, which you outlined, but have the users email address show up instead of just a default, or 'nobody' account.

splace
02-11-2004, 11:08 AM
Ok well in my original code, i took out the $from and put in $headers with the code you provided. That took care of the problem. Thanks!


Steve