PHP mail not functioning
My PHP contact form does not send my email anywhere, be it Inbox or Spam. The PHP is the latest edition and is running on a server which has SMTP installed on it. I'm unsure whether it's my code or software...
Heres my php contact script:
<?php
$to = "FILTERED";
$subject = $_POST['subject'];
$message = $_POST['message'] ." From: " .$_POST['email'];
$from = "contactform@contact.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
and my form:
<form method='post' action='contactscript.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input开发者_开发知识库 type='submit' />
</form>
To determine whether the problem lies in your code or in the external software, check the return value of mail()
.
if ( mail($to,$subject,$message,$headers) ) {
echo "Message was sent";
}
else {
echo "Sending failed.";
}
If it returns false, the error lies in your script, or the message was not accepted for delivery by your mail server.
I hope - $to = "FILTERED"; means you are putting the filtered email addresses in $to. If mail() is failing, you should get an error in PHP. Enable error reporting or check the log file. If mail() is not failing then it's no more a PHP issue, you should check the mail server. You can also try to send a mail using mail() with hard-coded values to see if the mail goes out.
Maybe add a space after the From colon?
$headers = "From:" . $from;
->
$headers = "From: " . $from;
But yes, either var_dump, or echo out mail():
echo mail($blah,...);
1 is success, 0 would be failure.
Also, $to doesn't seem to be a valid email address..
I would outsource it using something like sendgrid with a free plan of 200 messages per day. It makes sure your messages don't get flagged as spam because it using DKIM/SPF(not that easy to handle yourself) plus you don't have to worry about scaling.
Although you can change this with params and config variables, php mail() uses sendmail by default. If it is not installed in the standard location and you do not configure it explicitly to use another method, mail() will fail.
精彩评论