toolman Posted June 23, 2015 Share Posted June 23, 2015 Hi, I have the following script which sends an email, but it only displays the &message in the email. I would like to include the $from_name, $from_email and $telephone in the email as well. How would I do this? Thanks! if($_POST){ $to = 'me@me.com'; $subject = 'Signup'; $from_name = $_POST['name']; $company = $_POST['company']; $from_email = $_POST['email']; $telephone = $_POST['telephone']; $message = $_POST['message']; $robotest = $_POST['robotest']; if($robotest) $error = "You are a gutless robot."; else{ if($from_name && $from_email && $message){ $header = "From: $from_name <$from_email>"; if(mail($to, $subject, $message, $header)) $success = "You are human and your message was sent!"; else $error = "You are human but there was a problem sending the e-mail."; }else $error = "All fields are required."; } if($error) echo '<div class="msg error">'.$error.'</div>'; elseif($success) header ("location: contactthanks.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/296983-how-can-i-include-fields-in-the-body-of-an-email/ Share on other sites More sharing options...
Solution Barand Posted June 23, 2015 Solution Share Posted June 23, 2015 Then append them to the message $message = $_POST['message'] . "\n" . $_POST['name'] . "\n" . $_POST['email'] . "\n" . $_POST['telephone']; Quote Link to comment https://forums.phpfreaks.com/topic/296983-how-can-i-include-fields-in-the-body-of-an-email/#findComment-1514700 Share on other sites More sharing options...
toolman Posted June 23, 2015 Author Share Posted June 23, 2015 Nice, many thanks Quote Link to comment https://forums.phpfreaks.com/topic/296983-how-can-i-include-fields-in-the-body-of-an-email/#findComment-1514702 Share on other sites More sharing options...
toolman Posted June 23, 2015 Author Share Posted June 23, 2015 Hi, I'm not sure if I should open a new post for this, but I have two forms on the same page, one with an extra field and the details get submitted to a different email address. What would be the best way to have two lots of the above code on the page? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/296983-how-can-i-include-fields-in-the-body-of-an-email/#findComment-1514705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.