I wrote this code for sending email using PHP and upload it to a server, but it doesn't work:
<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are yo开发者_StackOverflow中文版u?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
It says "Message delivery failed..." every time!
Can anyone help?
I tried running your code on local server and this is the error i got:
"sendmail_from" not set in php.ini or custom "From:" header missing
You should probably set "From" header and it should work just fine
...
mail ($to,$subject,$body,'From: sender@example.com');
Antispam softwares are very picky, if you send emails that way you have few chanches to get them in your recipients' inbox. If you want more control on your messages, consider sending emails with a mailer library. http://swiftmailer.org/ is a really good choice. This is not a complete solution to spam problems, but it helps.
精彩评论