简体   繁体   中英

why is php mail script not sending mail

<?php 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("example@gmail.com", "hello", "nothing",$headers);
echo "mail sent";
?>

but it does not actually send the mail please help me out with this

The mail function is just an interface to the local mail server. The mail functionality in PHP relies on the machine PHP is running on to be correctly configured and able to dispatch e-mail. Check the mail system configuration on the machine.

check the following -

  1. check if your smtp server is running (you could either check through command line tools or try ftp'ing to port 25).
  2. If your smtp server is running. Then try to send a mail manually (without script). Use the command-line mail command (I am assuming you have unix here).

Also, when you run your script, what happens? It could be possible that your mail is in a Queue. From your terminal type 'mailq'. This shows the current emails in Queue & why they are there. Also there is a corresponding log to this. You could also check that out for info.

My guess is if all the above are running, you are good to go.

please check following ** Please verify your servers sender domain policy**

Emails sent through your servers (mail servers and shared web servers) should use a from address that is hosted here at your server. Emails that are sent with a from address hosted somewhere else (like Hotmail or Google) may be blocked.

ie use

$header = "From:example@/*yourhostname.domain name*/ \r\n";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM