Jump to content

Problem with mail()


mysty

Recommended Posts

I have a form named “myform” that has 5 fields in a page called form.php.  The fields are listed below:
Name
Address
Email
Phone
Comments

I have the form’s action = form_sent.php and the method is POST.
I cannot get all the fields sent to my email address (which is what I want).  What PHP code am I missing?  Here is the code in form_sent.php starting with line 1:

<?php
$to = "[email protected]";
$subject = "Comments";
$message = 'Name: '.$_POST['name']."\n\n";
$message = 'Address: '.$_POST['address']."\n\n";
$message = 'Email: '.$_POST['email']."\n\n";
$message = 'Phone: '.$_POST['phone']."\n\n";
$message = 'Comments: '.$_POST['comments']."\n\n";
$headers="From: " . $_POST['email'] . "\n";
Mail($to,$subject,$message,$headers);
?>

I get the email sent to $to and I get the $subject and ‘comments’ field.
Link to comment
https://forums.phpfreaks.com/topic/29343-problem-with-mail/
Share on other sites

each time you're intending to append the $message variable, you're actually overwriting it. a good ole full stop will do the trick:
[code]
<?php
$to = "[email protected]";
$subject = "Comments";
$message = 'Name: '.$_POST['name']."\n\n";
$message.= 'Address: '.$_POST['address']."\n\n";
$message.= 'Email: '.$_POST['email']."\n\n";
$message.= 'Phone: '.$_POST['phone']."\n\n";
$message.= 'Comments: '.$_POST['comments']."\n\n";
$headers="From: " . $_POST['email'] . "\n";
Mail($to,$subject,$message,$headers);
?>
[/code]
you have 5 lines starting with $message. notice i've change the $message = to $message.= which basically means it'll append new content to existing content, rather than setting it afresh.

cheers
Mark
Link to comment
https://forums.phpfreaks.com/topic/29343-problem-with-mail/#findComment-134584
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.