Simple Php mailer missing some bits
Question
I copied some PHP mailer and at some point had it working. But the thing is, I think it's missing something I want specifically, I need to make the final email output display like below:
Name: [name of sender here]
Subject: [subject here]
Message: [message here]
See if the format above can be done I would like to add a company input field too at some point. here's he php mailer below:
<?php
//print_r($_POST);
if(isset($_POST['_save'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if (empty($name) || empty($email) || empty($subject) || empty($message)) {
if (empty($name))
$error['name'] = "Please enter your Full Name";
if (empty($email))
$error['email'] = "Please enter a valid Email Address";
if (empty($subject))
$error['subject'] = "Please Write a Subject";
if (empty($message))
$error['message'] = "lease write a message, inquiries or other concerns above";
}
else { //if not empty
$headers="From: {$email}\r\nReply-To: {$email}"; //create headers for email
mail('email@domain.com',$subject,$message,$headers); //mail the message;
$success = "Thank you! You're email has been sent.";
#done;
}
}
?>
Solution
For your first question, change
mail('email@domain.com',$subject,$message,$headers);
to
$content="Name: ".$name."<br>Subject: ".$subject."<br>Message: ".$message;
mail('email@domain.com',$subject,$content,$headers);
As for your second question, as Jan states, add a company name field to your form and do exactly the same as with the name/subject/message variables.
OTHER TIPS
You can add the company input any time you want by just adjusting the following example:
$email_message = '
Name: ' . $name . '<br />
Subject: ' . $subject . '<br />
Message: ' . $message . '
';
$headers="From: {$email}\r\nReply-To: {$email}"; //create headers for email
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/alternative; boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n" .
"Your email application may not support this format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 8bit\n\n" .
$email_message;
$email = mail('email@domain.com',$subject,$email_message,$headers); //mail the message;
if($email){
$success = "Thank you! You're email has been sent.";
}
I adjusted your headers a bit with the example above because not every email client will accept your email. Tell me if this is what you need.