Confirmation Email will not send - php

So i have this contact form, everything sends fine after the submit button is pressed. However the confirmation email does not seem to send...
I couldnt find the answer on here anywhere, or i would not have asked
The Confirmation email code
<?php
$your_email = "jp.vaughan#icloud.com"; // email address to which the form data will be sent
$subject = "Contact Email";
$thanks_page = "/contact/thankyou.html";
if (isset($_POST["submit"])) {
$nam = $_POST["name"];
$ema = trim($_POST["email"]);
$org = trim($_POST["organisation"]);
$com = $_POST["comments"];
$loadtime = $_POST["loadtime"];
if (get_magic_quotes_gpc()) {
$nam = stripslashes($nam);
$ema = stripslashes($ema);
$org = stripslashes($org);
$com = stripslashes($com);
}
$error_msg=array();
if (empty($nam) || !preg_match("~^[a-z\-'\s]{1,60}$~i", $nam)) {
$error_msg[] = "The name field must contain only letters, spaces, dashes ( - ) and single quotes ( ' )";
}
if (empty($ema) || !filter_var($ema, FILTER_VALIDATE_EMAIL)) {
$error_msg[] = "Your email must have a valid format, such as name#mailhost.com";
}
if (empty($org) || !preg_match("~^[a-z\-'\s]{1,60}$~i", $org)) {
$error_msg[] = "The Organisation must contain only letters, spaces, dashes ( - ) and single quotes ( ' )";
}
$limit = 1000000000000000000000000000000000000;
if (empty($com) || !preg_match("/^[0-9A-Za-z\/-\s'\(\)!\?\.,]+$/", $com) || (strlen($com) > $limit)) {
$error_msg[] = "Your message must contain only letters, digits, spaces and basic punctuation ( ' - , . )";
}
$totaltime = time() - $loadtime;
if($totaltime < 7) {
echo("<p>Please fill in the form before submitting!</p>");
echo '</ul>
<form method="post" action="', $_SERVER['PHP_SELF'], '">
<input placeholder="Your Name*" name="name" type="text" id="name" value="'; if (isset($_POST["name"])) {echo $nam;}; echo '">
<input placeholder="Your Email Address*" name="email" type="email" id="email"'; if (isset($_POST["email"])) {echo $ema;}; echo '">
<input placeholder="Your Organisation*" name="organisation" type="text" id="organisation" value="'; if (isset($_POST["organisation"])) {echo $org;}; echo '">
<textarea placeholder="Your Message" name="comments" rows="5" cols="50" id="comm">'; if (isset($_POST["comments"])) {echo $com;}; echo '</textarea>
<input type="hidden" name="loadtime" value="', time(), '">
<input type="submit" name="submit" value=" SEND" id="submit">
</form>';
exit;
}
if ($error_msg) {
echo '
<p>Unfortunately, your message could not be sent. The form as you filled it out is displayed below. Make sure each field is completed. Please address any issues listed below:</p>
<ul class="err">';
foreach ($error_msg as $err) {
echo '<li>'.$err.'</li>';
}
echo '</ul>
<form method="post" action="', $_SERVER['PHP_SELF'], '">
<input placeholder="Your Name*" name="name" type="text" id="name" value="'; if (isset($_POST["name"])) {echo $nam;}; echo '">
<input placeholder="Your Email Address*" name="email" type="email" id="email"'; if (isset($_POST["email"])) {echo $ema;}; echo '">
<input placeholder="Your Organisation*" name="organisation" type="text" id="organisation" value="'; if (isset($_POST["organisation"])) {echo $org;}; echo '">
<textarea placeholder="Your Message" name="comments" rows="5" cols="50" id="comm">'; if (isset($_POST["comments"])) {echo $com;}; echo '</textarea>
<input type="hidden" name="loadtime" value="', time(), '">
<input type="submit" name="submit" value=" SEND" id="submit">
</form>';
exit();
}
$email_body =
"Name of sender: $nam\n\n" .
"Email of sender: $ema\n\n" .
"Organisaition: $org\n\n" .
"COMMENTS:\n\n" .
"$com" ;
if (!$error_msg) {
mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To: $nam <$ema>");
die ("Thank you. Your message has been sent to the appropriate person.");
exit();
}
$sendto = $_POST["email"]; // this is the email address collected form the form
$ccto = "jp.vaughan#icloud.com"; //you can cc it to yourself
$subjectCon = "Email Confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc...";
$header = "From: auto-confirm#moibrahimfoundation.org\r\n";
// This is the function to send the email
if(isset($_POST['submit'])) {
mail($sendto, $subjectCon, $message, $header);
}}
?>

you are exiting the code after sending the first email.
if (!$error_msg) {
if (mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To: $nam <$ema>");
die ("Thank you. Your message has been sent to the appropriate person."); //you are exiting here
exit(); //additional exit here. the second email won't be sent if there is no error.
}
$sendto = $_POST["email"]; // this is the email address collected form the form
$ccto = "jp.vaughan#icloud.com"; //you can cc it to yourself
$subjectCon = "Email Confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc...";
$header = "From: auto-confirm#moibrahimfoundation.org\r\n";
// This is the function to send the email
if(isset($_POST['submit'])) {
mail($sendto, $subjectCon, $message, $header);
should be
$success='';
if (!$error_msg) {
if (mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To: $nam <$ema>")){
$success="Thank you. Your message has been sent to the appropriate person.";
}else{
$success="Your message cannot be sent";
}
}
$sendto = $_POST["email"]; // this is the email address collected form the form
$ccto = "jp.vaughan#icloud.com"; //you can cc it to yourself
$subjectCon = "Email Confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc...";
$header = "From: auto-confirm#moibrahimfoundation.org\r\n";
// This is the function to send the email
if(isset($_POST['submit'])) {
mail($sendto, $subjectCon, $message, $header);
die($success);
if your first mail is also not sending please check the mail configuration in your php.ini and verify that you can send mail through it.

use this tool for checking ur mail is sending or not...also it will show all parameters of mail function...
Test Tool

Related

sendmail.php not re-directing

I had/have the code below for users to send messages/emails from my website to my sites email address.
It was working fine, for weeks: Validating the field contents (if there was a blank 'required field', it asked for a "valid" field content i.e. email address), as long as there were no blank fields it was sending the email and was re-directing to the thank-you page - which acknowledges that the email has been sent.
Now, it has stopped working properly.
It doesn't seem to be validating (as it did originally) any more - as there are no warnings/errors for blank fields (if there is a blank field it simply doesn't send), it still sends the email to the address correctly (if there are no blank required fields), but it doesn't redirect to the thank-you page any more.
Here is the form code:
<form method="post" action="assets/sendmail.php">
<label for="name" class="nameLabel">Name</label>
<input id="name" type="text" name="name" placeholder="Enter your name...">
<label for="email" class="emailLabel">Email</label>
<input id="email" type="text" name="email" placeholder="Enter your email...">
<label for="subject">Subject</label>
<input id="subject" type="text" name="subject" placeholder="Your subject...">
<label for="message" class="messageLabel">Message</label>
<textarea id="message" name="message" placeholder="Your message..."></textarea>
<button type="submit">Send</button>
</form>
Here is the php code - note that I have substituted the email address for obvious reasons :)
<?php
// Email address verification
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email));
}
if($_POST) {
// Enter the email where you want to receive the message
$emailTo = 'me#myemail.com';
$clientName = trim($_POST['name']);
$clientEmail = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$array = array();
$array['nameMessage'] = '';
$array['emailMessage'] = '';
$array['messageMessage'] = '';
if($clientName == '') {
$array['nameMessage'] = 'Please enter your name.';
}
if(!isEmail($clientEmail)) {
$array['emailMessage'] = 'Please insert a valid email address.';
}
if($message == '') {
$array['messageMessage'] = 'Please enter your message.';
}
if($clientName != '' && isEmail($clientEmail) && $message != '') {
// Send email
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
mail($emailTo, $subject, $message, $headers);
}
//echo json_encode($array);
{
header("location:../thankyou.html");
}
}
?>
Any help would be appreciated.
First of all, for email checking you can use built-in php as well.
filter_var($clientEmail, FILTER_VALIDATE_EMAIL)
I don't see where you output your errors so that may be why they are not showing,
I have added support for that
I have rewritten your code:
<?php
if (!empty($_POST)) {
// Enter the email where you want to receive the message
$emailTo = 'me#myemail.com';
$clientName = trim($_POST['name']);
$clientEmail = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$errors = array();
if (empty($clientName)) {
$errors['nameMessage'] = 'Please enter your name.';
}
if (!filter_var($clientEmail, FILTER_VALIDATE_EMAIL)) {
$errors['emailMessage'] = 'Please insert a valid email address.';
}
if (empty($message)) {
$errors['messageMessage'] = 'Please enter your message.';
}
// Are there errors?
if (count($errors) == 0) {
// Send email
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
mail($emailTo, $subject, $message, $headers);
header("location:../thankyou.html");
} else {
foreach ($errors as $err) {
echo $err . '<br />';
}
}
}
?>
Thank-you for the updated PHP code. Unfortunately, it hasn't made any difference. It still sends the email when all fields are filled in, it even sends if the "subject" is empty, but it still does not re-direct to the thank-you page. It doesn't send if Name, Email Address, and Message are empty. But it does not display errors. I have tried to place both files in the parent directory and removing the assets/ from the action in the form and the ../ in the PHP. as below
<form method="post" action="sendmail.php">
<label for="name" class="nameLabel">Name</label>
<input id="name" type="text" name="name" placeholder="Enter your name...">
<label for="email" class="emailLabel">Email</label>
<input id="email" type="text" name="email" placeholder="Enter your email...">
<label for="subject">Subject</label>
<input id="subject" type="text" name="subject" placeholder="Your subject...">
<label for="message" class="messageLabel">Message</label>
<textarea id="message" name="message" placeholder="Your message..."></textarea>
<button type="submit">Send</button>
</form>
And the PHP is as you supplied (changing the email address of course)
<?php
if (!empty($_POST)) {
// Enter the email where you want to receive the message
$emailTo = 'me#myemail.com';
$clientName = trim($_POST['name']);
$clientEmail = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$errors = array();
if (empty($clientName)) {
$errors['nameMessage'] = 'Please enter your name.';
}
if (!filter_var($clientEmail, FILTER_VALIDATE_EMAIL)) {
$errors['emailMessage'] = 'Please insert a valid email address.';
}
if (empty($message)) {
$errors['messageMessage'] = 'Please enter your message.';
}
// Are there errors?
if (count($errors) == 0) {
// Send email
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
mail($emailTo, $subject, $message, $headers);
header("location:thankyou.html");
} else {
foreach ($errors as $err) {
echo $err . '<br />';
}
}
}
?>
No Errors displayed if there are errors, no re-direct once sent. It just remains on the "contact" page and still displaying the completed form. Cannot understand why the re-direct was working but not now. Couldn't sign in when I posted this originally.

PHP email contact form displays error

Every time I attempt to submit this contact form I receive the following error message:
'Please enter your message.'
The name error message and email error message do not appear unless I leave them blank. I attempted specifying post in the HTML.
Here is the HTML:
<div class="col-md-8 animated fadeInLeft notransition">
<h1 class="smalltitle">
<span>Get in Touch</span>
</h1>
<form action="contact.php" method="post" name="MYFORM" id="MYFORM">
<input name="name" size="30" type="text" id="name" class="col-md-6 leftradius" placeholder="Your Name">
<input name="email" size="30" type="text" id="email" class="col-md-6 rightradius" placeholder="E-mail Address">
<textarea id="message" name="message" class="col-md-12 allradius" placeholder="Message" rows="9"></textarea>
<img src="contact/refresh.jpg" width="25" alt="" id="refresh"/><img src="contact/get_captcha.php" alt="" id="captcha"/>
<br/><input name="code" type="text" id="code" placeholder="Enter Captcha" class="top10">
<br/>
<input value="Send" type="submit" id="Send" class="btn btn-default btn-md">
</form>
</div>
Here is the PHP:
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course, you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$comment) $errors[count($errors)] = 'Please enter your message.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - replace your email here
$to = 'faasdfsdfs#gmail.com';
//sender - from the form
$from = $name . ' <' . $email . '>';
//subject and the html message
$subject = 'Message from ' . $name;
$message = 'Name: ' . $name . '<br/><br/>
Email: ' . $email . '<br/><br/>
Message: ' . nl2br($comment) . '<br/>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
In your HTML form you name your <input... field "message" but then when you are in PHP you try to get the value from `$_GET['comment'].
I think if you get those lined up I think it will solve your problem.
I can see 2 issues:
Receive $_GET['comment'] or $_POST['comment'] but next you're using $message var
Do not use if($_POST) because $_POST as a superglobal
is always setted.
I suggest use this for check if a POST have been sent
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {}
or this in case you want to check is not empty
if ( !empty($_POST) ) {}
How to detect if $_POST is set?

PHP mail form is not working

I m having a problem with my email php form, when I click in the submit button an other page shows up saying There was a problem with your e-mail ()
I don't no what I am doing wrong?
here is my code:
html code
<!-- Subscription Form -->
<form class="email" action="form.php" method="post">
<input class="get_notified" type="text" placeholder="Enter your email address ..."/>
<button type="submit" class="go" /></form>
<!-- End Subscription Form -->
</div>
</div>
</body>
php code
<?php
$to = "email#mydomain.com";
$from = "email#mydomain.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
You'll need to add a name="email" field to your HTML form in order for PHP to be able to fetch it using $_POST['email']
<input class="get_notified" name="email" type="text" placeholder="Enter your email address ..."/>

My PHP Contact Form is not working

I am creating a website and I was making a contact form with PHP. It is turning up no errors on the page itself but the email never shows up in the inbox or spam folder of my email. The code I have for it is:
$_NAME = $_POST["name"];
$_EMAIL = $_POST["reply"];
$_SUBJECT = $_POST["subject"];
$_MESSAGE = $_POST["message"];
$_MAILTO = "myemail#gmail.com";
$_SUBJECT = "Contact Form";
$_FORMCONTENT = "From: ".$_NAME." Subject: ".$_SUBJECT." Message: ".$_MESSAGE;
$_MAILHEADER = "Reply To: ".$_EMAIL;
mail($_MAILTO, $_SUBJECT, $_FORMCONTENT, $_MAILHEADER);
Any ideas what the problem is?
EDIT --
Here's the HTML form:
<form id="contact" name="contact" action="contact2.php" method="post">
<input type="text" class="name" name="name" id="name" placeholder="Your name (optional)" onfocus="placeholder=''" onblur="placeholder='Your name (optional)'" /><br><br>
<input type="text" class="reply" id="reply" name="reply" placeholder="Your email (optional)" onfocus="placeholder=''" onblur="placeholder='Your email (optional)'" /><br><br>
<input type="text" class="subject" id="subject" name="subject" placeholder="Subject" onfocus="placeholder=''" onblur="placeholder='Subject'" /><br><br>
<textarea class="message" id="message" name="message" rows="10" cols="50" placeholder="Enter your message" onfocus="placeholder=''" onblur="placeholder='Enter your message'"></textarea><br><br>
<input type="submit" class="send" id="send" name="send" value="Send Message" />
</form>
First step would be to check the return value of the mail function to see if the email was successfully (as far as PHP/mail function can ascertain) sent.
$mail_result = mail($_MAILTO, $_SUBJECT, $_FORMCONTENT, $_MAILHEADER);
if ($mail_result) {
echo <<<HTML
<div>Mail was successfully sent!</div>
HTML;
} else {
echo <<<HTML
<div>Sending mail failed!</div>
HTML;
}
Secondly, you should check that all appropriate settings are correctly set in your php.ini file, specifically the sendmail_path setting. You should definitely take a look at official documentation in the PHP Manual.
As a last ditch effort, you may want to look into an alternate method of sending the mail.
Simple Example:
<?php
// Has the form been submitted?
if (isset($_POST['send'])) {
// Set some variables
$required_fields = array('name', 'email'); // add fields as needed
$errors = array();
$success_message = "Congrats! Your message has been sent successfully!";
$sendmail_error_message = "Oops! Something has gone wrong, please try later.";
// Cool the form has been submitted! Let's loop
// through the required fields and check
// if they meet our condition(s)
foreach ($required_fields as $fieldName) {
// If the current field in the loop is NOT part of the form submission -OR-
// if the current field in the loop is empty
if (!isset($_POST[$fieldName]) || empty($_POST[$fieldName])) {
// add a reference to the errors array, indicating that these conditions have failed
$errors[$fieldName] = "The {$fieldName} is required!";
}
}
// Proceed if there aren't any errors
if (empty($errors)) {
// add fields as needed
$name = htmlspecialchars(trim($_POST['name']), ENT_QUOTES, 'UTF-8' );
$email = htmlspecialchars(trim($_POST['email']), ENT_QUOTES, 'UTF-8' );
// Email receivers
$to_emails = "anonymous1#example.com, anonymous2#example.com";
$subject = 'Contact form sent from ' . $name;
$message = "From: {$name}";
$message .= "Email: {$email}";
$headers = "From: {$name}\r\n";
$headers .= "Reply-To: {$email}\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if (mail($to_emails, $subject, $message, $headers)) {
echo $success_message;
} else {
echo $sendmail_error_message;
}
} else {
foreach($errors as $invalid_field_msg) {
echo "<p>{$invalid_field_msg}</p>";
}
}
}

Need some help with a HTML form PHP send email combo platter

PHP has never been my strong suit so I need some assistance getting the contents of a form to send via email properly in PHP.
Here is the html form:
<form action="estimate.php" method="post" >
<fieldset>
<input type="text" class="required" name="name" value="FULL NAME*" onfocus="if (this.value=='FULL NAME*') this.value='';"/>
<input type="text" class="required" name="phone" value="PHONE NUMBER*" onfocus="if (this.value=='PHONE NUMBER*') this.value='';"/>
<input type="text" class="required" name="email" value="EMAIL*" onfocus="if (this.value=='EMAIL*') this.value='';"/>
<input type="text" class="required" name="date" value="MOVE DATE*" onfocus="if (this.value=='MOVE DATE*') this.value='';"/>
<input type="text" class="required" name="origin" value="ORIGINATING ADDRESS*" onfocus="if (this.value=='ORIGINATING ADDRESS*') this.value='';"/>
<input type="text" name="destination" value="DESTINATION ADDRESS" onfocus="if (this.value=='DESTINATION ADDRESS') this.value='';"/>
<select name="move-type">
<option value="" selected="selected">TYPE OF MOVE</option>
<option value="Private">Private</option>
<option value="Commercial">Commercial</option>
</select>
<input id="quoteSubmit"
type="image" src="_images/btn_submit.png" alt=""
onmouseover="javascript:this.src='_images/btn_submit-over.png'"
onmouseout="javascript:this.src='_images/btn_submit.png'"/>
</fieldset>
</form>
Here is the PHP I have thus far:
<?php
$emailFromName = $_POST['name'];
$emailFromPhone = $_POST['phone'];
$emailFrom = $_POST['email'];
$emailDate = $_POST['date'];
$emailOrigin = $_POST['origin'];
$emailDestination = $_POST['destination'];
$emailType = $_POST['move-type'];
if (empty($emailFromName)) {
echo 'Please enter your name.';
} elseif (!preg_match('/^([A-Z0-9\.\-_]+)#([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'The email address entered is invalid.';
} elseif (empty($emailDate)) {
echo 'You must enter a Move date.';
} elseif (empty($emailOrigin)) {
echo 'You must enter a message.';
} elseif (empty($emailDestination)) {
echo 'You must enter a message.';
} else {
$emailTo = "info#movingsimple.com";
if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "The Boss" <noreply#movingsimple.com>';
}
/* Send Email */
if (mail($emailTo, $emailSubject, $emailDate, $emailHeaders)) {
echo 'Thank you! Your message has been sent.';
} else {
echo 'There was an internal error while sending your email.<br>';
echo 'Please try again later.';
}
}
?>
I am having trouble with the body of the message. I need to display all the values from the form:
From:
Email:
Phone:
Move date:
Origin:
Destination:
Move type:
but I am not exactly sure how to compile all those into the body and would appreciate some help.
thanks.
Update this part of the code
if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "The Boss" <noreply#movingsimple.com>';
}
/* Send Email */
if (mail($emailTo, $emailSubject, $emailDate, $emailHeaders)) {
echo 'Thank you! Your message has been sent.';
to generate a string containing the body of the email:
if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "The Boss" <noreply#movingsimple.com>';
}
// Create a string representing the body. "\n" creates a new line.
// The ".=" operator appends the string onto the existing string.
$body = "From: ".$emailFromName."\n";
$body .= "Email: ".$emailFrom."\n";
$body .= "Phone: ".$emailFromPhone."\n";
$body .= "Move Date: ".$emailDate."\n";
$body .= "Origin: ".$emailOrigin."\n";
$body .= "Destination: ".$emailDestination."\n";
$body .= "Move Type: ".$emailType."\n";
/* Send Email */
if (mail($emailTo, $emailSubject, $body, $emailHeaders)) {
echo 'Thank you! Your message has been sent.';
// ... rest of the code ...
The third parameter of the mail() function (http://us.php.net/manual/en/function.mail.php) is the message, so we create the message as a string ($body) and then pass it as a parameter to the mail() function.
Small Update: The PHP mail() help page says to use "\n" as a line ending rather than "\r\n"
The third attribute to the mail function is for body of the email not date like you are specifying $emailDate, you should specify the email body there.
Right now you're sending the $emailDate as the body of the message.. You just need to build a variable with the data you want. i.e.
$emailBody = "Move date: " . $emailDate;
I think your header variable needs to have a \r\n at the end, too.

Categories