mysty Posted December 3, 2006 Share Posted December 3, 2006 I have a form named “myform” that has 5 fields in a page called form.php. The fields are listed below:NameAddressEmailPhoneCommentsI 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 More sharing options...
redbullmarky Posted December 4, 2006 Share Posted December 4, 2006 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.cheersMark Link to comment https://forums.phpfreaks.com/topic/29343-problem-with-mail/#findComment-134584 Share on other sites More sharing options...
mysty Posted December 4, 2006 Author Share Posted December 4, 2006 Thanks. That was just what I needed. Everything is working fine now. Link to comment https://forums.phpfreaks.com/topic/29343-problem-with-mail/#findComment-134598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.