On my website there is a contact form, for some reason after filling out the form, I won't get an email.
Below is the code for the form followed by the code for the sendmail.php code page. *For privacy I removed my email and replaced it with email#domain.com
Anyone know what could be wrong?
Thanks in advance,
Peter
contact.html Page Snip --
<div class="contact-us container">
<div class="row">
<div class="contact-form span7">
<p>Please fill out the form below and we'll get back to you as soon as we can! </p>
<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>
</div>
</div>
</div>
Sendmail.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 = 'email#doamin.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);
}
?>
Try changing if($_POST) to if( ! empty($_POST)). Also try var_dump($_POST); at the top of the page to make sure you're getting the variables through properly.
In my working contact form in php i use following verification:
if(isset($_POST['email']))
{
// your send mail code
}
BTW if you call directly:
mail("youremail#domain" , " your subject" , " mail body" , "From: example#example.com" );
your mail arives in inbox? i ask because you may not have acces to sendmail function from php.
1. Using
Your'e using PHP - Why you dont use functions that provides by PHP?
isEmail is nonsense, use filter_var to validate E-Mails:
if(filter_var($clientEmail, FILTER_VALIDATE_EMAIL)) {
// E-Mail is valid
}
2. POST Requests
To check if the post-request is taken, use isset or empty:
if(isset($_POST)) {
// Send the mail...
}
If you're using more than one form with an POST-Request on your side, be sure that you only handle the correct form. To prevent the problem, add an name attribute on your submit-button and check it:
if(isset($_POST['yourFirstButton'])) {
// Handle the first form
}
And
<input type="submit" name="yourFirstButton" value="Send" />
3. Use correct mail headers
Mail-Headers must be valid. A Propertie is Name: Value\r\n and NOT Name: Value.
You must add an \r\n at your last entry:
$headers = "From: " . $clientName . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail . "\r\n";
4. Can your server send mails?
If you dont receive mails, check your server configuration or ask your server administrator. PHP must be configured to sending mails. Install sendmail for example. Otherwise fill out the SMPT settings in your PHP-Configuration (php.ini) to send a mail over an mailserver.
5. Using mail
Why you use the mail function? Mostly you (the programmer) must deal with headers and other to send a valid mail - Otherwise, the mailserver decline/bounce the mail or the mail goes to your spam folder.
If you're using mail, check the output:
$test = mail(/* Your parameters */);
var_dump($test);
If it's returned 1 or true, PHP says that the mail was probably sent.
Use an PHP Mailer class like PHPMailer (https://github.com/PHPMailer/PHPMailer)
Related
I am aware there are other subjects with similar questions however their answered didn't solve my problem.
I developed a website and temporarily decided to go ahead and use PHP mail as opposed to other routes as it was the quickest and easiest (I am an amateur developer). It was working flawlessly for the past month with no issues, however 3 days ago, I started receiving emails with no message contents (these are not spam or just empty messages, I am aware that I should use validation etc).
I still successfully receive the email to my email account, it also contains the subject header being "Contact Form Request", however the body is empty i.e. $msg that should be populated aren't?
I switched over the placement of "Contact Form Request" and $msg and the $msg contents would be received in the email subject header so it is being populated, however the message body remains empty.
Any help would be appreciate.
contact.html
<div id="contact-form">
<form action="contact.php" method="post">
<div class="form-group">
<label for="inputName">Name *</label>
<input type="text" class="form-control" name="name" placeholder="Enter name" required>
</div>
<div class="form-group">
<label for="inputNumber">Contact Number *</label>
<input type="tel" class="form-control" name="phone" placeholder="Enter contact number" required inputMode="tel">
</div>
<div class="form-group">
<label for="inputEmail">Email *</label>
<input type="email" class="form-control" name="email" placeholder="Enter email" required>
</div>
<div class="form-group">
<label for="inputSubject">Subject *</label>
<input type="text" class="form-control" name="subject" placeholder="Enter subject" required>
</div>
<div class="form-group">
<label for="inputMessage">Message *</label>
<textarea type="text" class="form-control" name="message" placeholder="Enter message" rows="3" required maxlength="300"></textarea>
</div>
<p><small><strong>*</strong> These fields are required.</small></p>
<button type="submit" class="btn btn-send">Send</button>
</form>
</div>
contact.php
<?php
$webmaster_email = "test#drivingschool.co.uk";
$success_page = "thankyoucontact.html";
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$msg =
"You have received a message from " . $name . "\r\n\n" .
"Subject: " . $subject . "\r\n\n" .
"Message: " . $message . "\r\n\n" .
"Name: " . $name . "\r\n" .
"Phone: " . $phone . "\r\n" .
"Email: " . $email . "\r\n\n\n\n" .
"DISCLAIMER:\r\n\nThis e-mail and any attachments is a confidential correspondence intended only for use of the individual or entity named above. If you are not the intended recipient or the agent responsible for delivering the message to the intended recipient, you are hereby notified that any disclosure, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender by phone or by replying this message, and then delete this message from your system.";
mail($webmaster_email, "Contact Form Request", $msg);
header("Location: $success_page");
?>
Your code looks OK on first inspection (not SAFE, but working).
My advise:
FIRST: Debug. Just show the message instead of actual mailing. Like hereunder:
<?php
$webmaster_email = "test#drivingschool.co.uk";
$success_page = "thankyoucontact.html";
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$msg =
"You have received a message from " . $name . "\r\n\n" .
"Subject: " . $subject . "\r\n\n" .
"Message: " . $message . "\r\n\n" .
"Name: " . $name . "\r\n" .
"Phone: " . $phone . "\r\n" .
"Email: " . $email . "\r\n\n\n\n" .
"DISCLAIMER:\r\n\nThis e-mail and any attachments is a confidential correspondence intended only for use of the individual or entity named above. If you are not the intended recipient or the agent responsible for delivering the message to the intended recipient, you are hereby notified that any disclosure, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender by phone or by replying this message, and then delete this message from your system.";
echo "The message contains: $msg";
exit;
// mail($webmaster_email, "Contact Form Request", $msg);
// header("Location: $success_page");
?>
If your message contains what you expect, you must look into the email gateway. This is much harder.
I would start by making a script like this, call it testmail.php with only this inside, and see if that works.
<?php
mail('test#drivingschool.co.uk', "testing", "testing.\nDoes this arrive?");
?>
EDIT: Third thing to check:
You are sending a plain text mail. Maybe your email client only displays HTML email? Please check.
EDIT: Fourth suggestion:
I would try the mail utility itself from commandline to check if your PHP is acting strange.
So if you have SHELL access (BASH or whatever) try something like this:
mail -s "Testing mail" test#drivingschool.co.uk <<< 'Testing. Is this body visible?'
If THAT fails too, go have a chat with your hosting provider.
If that works: Something is wrong with your PHP in combination with sendmail.
Here is some background:
https://www.binarytides.com/linux-mail-command-examples/
Set from email with the header. You can also use content-type text/html if message in HTML format
$from ='testmail#mail.com';
$headers = "From:" . $from . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
#mail($webmaster_email,$subject,$message,$headers);
Hope this work
I have the same error, I think that the mail function interprets the text:
Message: $msg
as header, this may be a bug in PHP or the way SMTP works.
Here is my code:
function send_email($to, $subject, $message) {
$headers[] = 'from: kurs#jcubic.pl';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, implode(PHP_EOL, $headers));
}
send_email("mail#example.com", 'Subscription', "Email: $email");
it works fine when I remove the colon from the message.
send_email("mail#example.com", 'Subscription', "Email $email");
My PHP form isn't submitting successfully. I keep getting the custom error that I wrote ('Oops there was a problem. Please try again").
any help would be greatly appreciated. I'm totally new to PHP so I'm thinking maybe some of my php variables are linked wrong and arent connecting with my mailer-new.php file?
Thanks in advance,
<section class="form-body">
<form method="post" action="mailer-new.php" class="contact-form" >
<div class="row">
<?php
if ($_GET['success']== 1){
echo " <div class=\"form-messages success\"> Thank you!
your message has been sent. </div>";
}
if ($_GET['success']== -1){
echo " <div class=\"form-messages error\"> Opps there was a
problem. Please try again </div>";
};
?>
<div class="field name-box">
<input type="text" name="name" id="name" placeholder="Who
Are You?" required/>
<label for="name">Name</label>
<span class="ss-icon">check</span>
</div>
<div class="field email-box">
<input type="text" name="email" id="email"
placeholder="name#email.com" required/>
<label for="email">Email</label>
<span class="ss-icon">check</span>
</div>
<div class="field msg-box">
<textarea name="message" id="msg" rows="4"
placeholder="Your message goes here..."/></textarea>
<label for="message">Msg</label>
<span class="ss-icon">check</span>
</div>
<input class="button" type="submit" value="Send"/>
</div>
</form>
</section>
MAILER.PHP
<?php
// Get the form fields, removes html tags and whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"), array(" ", " " ), $name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
// Check the data.
if (empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: http://www.conallen.ie/index.php?
success=-1#form");
exit;
}
// Set the recipient email address. Update this to YOUR desired email address.
$recipient = "allenconallen46#gmail.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
mail($recipient, $subject, $email_content, $email_headers);
// Redirect to the index.html page with success code
header("Location: http://www.conallen.ie/index.php?success=1#form");
?>
This code works correctly in my local machine, even though email is not sent response messages are coming correctly. The changes I have done is changed the host name and made the two lined header redirect into one line in the failed response. Also you have mentioned in the HTML the file name as action="mailer-new.php" and the file name mentioned in the question as MAILER.PHP. Are they same in the code?
To check whether the mail is sent or not remove the header redirect and update like this. If you are getting a failed response means mail is not configured in your server.
if(mail($recipient, $subject, $email_content, $email_headers)) {
echo "mail sent";
} else {
echo "mail sent failed";
}
Alternatively you can use the SMTP for sending email. You can use a library called PHP Mailer and can use any of the valid email address like a gmail account. Please have look at this question if that's the case
Sending email with PHP from an SMTP server
I'm using a template for my website that I found online. It came with a contact form html page and a sendmail php file. The form works and I receive the email in my inbox, but, for some reason, after I hit the 'send' button, the browser redirects to a blank page with the following (error?) message:
" {"nameMessage":"","emailMessage":"","messageMessage":""} "
The only thing that I can think of that I've changed (in the php file) is the email address where the messages are sent.
I am wondering how I can avoid this message and redirect to another page (thanks.html) instead?
Specifically, what code do I need to add, remove or replace to fix this issue please?
Here is the HTML and PHP code:
HTML:
<div class="contact-us container">
<div class="row">
<div class="contact-form span7" html_id="contactfrm">
<p>Want to get in touch? Use the form below to send an email.</p>
<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 id="button">Send</button>
</form>
</div>
</div>
</div>
PHP:
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 = 'email#gmail.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);
}
?>
p.s. I've noticed that there have been previous posts regarding this issue but I'm quite a newbie (especially with PHP).
After you have written
echo json_encode($array);
write ,
header('Location:thanks.php');
this will redirect you to thanks.php page and there you can write your html/php code.
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?
This is my code and my form... it acts like the email was sent, but it never arrives.
I would like to know what could possibly be wrong... Anyone?
The website is hosted on a Linux server, and I don't really know if the server could be blocking the emails because of some kind of incompatibility... I don't really know what it could be.
<?php
if($_POST)
{
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die();
}
$to_Email = "myemail#gmail.com"; //Replace with recipient email address
$subject = 'Ah!! My email from Somebody out there...'; //Subject line for emails
//check $_POST vars are set, exit if any missing
if(!isset($_POST["userName"]) || !isset($_POST["userEmail"]) || !isset($_POST["userPhone"]) || !isset($_POST["userMessage"]))
{
die();
}
//Sanitize input data using PHP filter_var().
$user_Name = filter_var($_POST["userName"], FILTER_SANITIZE_STRING);
$user_Email = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
$user_Phone = filter_var($_POST["userPhone"], FILTER_SANITIZE_STRING);
$user_Message = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING);
//additional php validation
if(strlen($user_Name)<4) // If length is less than 4 it will throw an HTTP error.
{
header('HTTP/1.1 500 Name is too short or empty!');
exit();
}
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
header('HTTP/1.1 500 Please enter a valid email!');
exit();
}
if(!is_numeric($user_Phone)) //check entered data is numbers
{
header('HTTP/1.1 500 Only numbers allowed in phone field');
exit();
}
if(strlen($user_Message)<5) //check emtpy message
{
header('HTTP/1.1 500 Too short message! Please enter something.');
exit();
}
//proceed with PHP email.
$headers = 'From: '.$user_Email.'' . "rn" .
'Reply-To: '.$user_Email.'' . "rn" .
'X-Mailer: PHP/' . phpversion();
#$sentMail = mail($to_Email, $subject, $user_Message .' -'.$user_Name, $headers);
if(!$sentMail)
{
header('HTTP/1.1 500 Couldnot send mail! Sorry..');
exit();
}else{
echo 'Hi '.$user_Name .', Thank you for your email! ';
echo 'Your email has already arrived in my Inbox, all I need to do is Check it.';
}
}
?>
Here's my form:
<fieldset id="contact_form">
<legend>My Contact Form</legend>
<div id="result"></div>
<input type="text" name="name" id="inputt" placeholder="Enter Your Name" />
<input type="text" name="email" id="inputt" placeholder="Enter Your Email" />
<input type="text" name="phone" id="inputt" placeholder="Phone Number" />
<textarea name="message" id="message" placeholder="Enter Your Name"></textarea>
<button class="submit_btn" id="submit_btn">Submit</button>
</fieldset>
Your $headers are wrong, you're appending "rn" instead of "\r\n". Try this instead:
$headers = 'From: '.$user_Email. "\r\n" .
'Reply-To: '.$user_Email. "\r\n" .
'X-Mailer: PHP/' . phpversion();
According from your comment out of the maillog you need to adjust your php.ini to include the --r argument to your sendmail_path.
By default it usually is:
sendmail_path = /usr/sbin/sendmail -t -i
Apparently you are using another argument that also requires the --r argument. Appending that to your sendmail_path should get a long way.