Forum Moderators: coopster

Message Too Old, No Replies

php form email help

newbie needs help with php form-from not working!

         

Sari

8:11 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



Hello!

I'm pretty much a newbie to php, but learning quickly (there's nothing like trial by fire!) ;)

My client wants a simple form on her site, which emails the user's answers to her. Sounds simple enough--but, she wants the user's email to be picked up by the form and placed in the "from" field on the email. This is where I'm having problems. I can get the form to send and everything is appearing in the email except the from field shows "client@clientsservername.com" instead of the email address which was typed into the form.

Here's the code I'm using right now:

<?php
// ************Begin Configure***************
//Put your subject in here
$subject = "form submission";

// ************End Configure****************

$message = "";

foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key . ":" . $value . "\n";
}
mail('me@mydomain.com', $subject, $message, $email);
?>

I've also tried defining $from = "From: $email"; and changing the mail line to:
mail('me@mydomain.com', $subject, $message, $from);

This changes the from field in the email to $email@servername.com

Any help with this would be greatly appreciated!

rubenski

8:26 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



This works for me:

$subject="Email from website";
$recipient = "Rubenski <rubenski@mydomain.com>";
$headers="From: $email_address_user\r\nReply-to: $email_address_user";
mail($recipient, $subject, $message, $headers);

Sari

9:47 pm on Jul 28, 2004 (gmt 0)

10+ Year Member



Hi Rubenski--thanks for the quick reply. I tried it and it didn't work! :( The form appeared to be submitting (i.e there were no error messages displayed), but the email didn't send.

Any other suggestions?

dkin

12:46 am on Jul 29, 2004 (gmt 0)

10+ Year Member



Try this

$to = "me@mydomain.com";
$subject = "Form Submission";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "From: $email <$email>\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

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

make sure that the $email variable is the same as the name as the form field or variable if you have it predefined

I think this should work.

Sari

10:32 am on Jul 29, 2004 (gmt 0)

10+ Year Member



It works! :)

Thanks dkin!