Jump to content

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 = "myemailaddress@emailserver.com";
$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 = "myemailaddress@emailserver.com";
$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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.