在localhost上从php发送电子邮件
I am using XAMPP with Mercury and Thunderbird. When I send a message through Mercury, the message works fine and I receive the email on Thunderbird. When I try in a PHP script, it does not.
I am certain it has something to do with php but I haven't been able to find a solution as to why it is not sending.
I'm not getting any errors either and it's saying the message was sent.
mailtest.php:
$to = "patrick@localhost";
$subject = "hi";
$body="text".PHP_EOL;
$body.="this message was sent".PHP_EOL;
$headers = "From: postmaster@localhost";
if (mail($to, $subject, $body, $headers)) {
echo "message sent!";
}
else {
echo "failed";
}
?>
php.ini:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 25
; I am on Windows 7 64bit
; For Win32 only.
; http://php.net/sendmail-from
; sendmail_from = localhost
sendmail.ini
smtp_server=localhost
smtp_port=25
我正在使用XAMPP与Mercury和Thunderbird。 当我通过Mercury发送消息时,消息正常,我收到了Thunderbird上的电子邮件。 当我尝试PHP脚本时,它没有。 p>
我确定它与php有关但我无法找到解决它为什么不发送的解决方案。 p>
我也没有收到任何错误,它说消息已发送。 p>
mailtest.php: p>
$ to =“patrick @ localhost”;
$ subject =“hi”;
$ body =“text”.PHP_EOL;
$ body。=“此消息已发送”.PHP_EOL;
$ headers =“来自: postmaster @ localhost“;
if(mail($ to,$ subject,$ body,$ headers)){
echo”message sent!“;
}
else {
echo”failed“; \ n}
?>
code> pre>
php.ini: p>
[mail function]
; XAMPP:如果你想使用像Mercury这样的SMTP服务器,请注释掉这个服务器
SMTP = localhost
smtp_port = 25
; 我在Windows 7 64bit
; 仅适用于Win32。
; http://php.net/sendmail-from
; sendmail_from = localhost
code> pre>
sendmail.ini p>
smtp_server = localhost
smtp_port = 25
code> pre>
div>
Use this sendmail program to use with an SMTP account like a gmail account. Here is the main project site http://glob.com.au/sendmail/ and here is a quick howto from another answer on SO https://stackoverflow.com/a/11210090/209067
This is i what use for my local windows environment, i just can't find the full article tutorial where i learned about it.