简体   繁体   English

在localhost上从php发送电子邮件

[英]Sending email from php on localhost

I am using XAMPP with Mercury and Thunderbird. 我正在使用XAMPP与Mercury和Thunderbird。 When I send a message through Mercury, the message works fine and I receive the email on Thunderbird. 当我通过Mercury发送消息时,消息正常,我收到了Thunderbird上的电子邮件。 When I try in a PHP script, it does not. 当我尝试PHP脚本时,它没有。

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. 我确定它与php有关,但我无法找到解决方案,为什么它不发送。

I'm not getting any errors either and it's saying the message was sent. 我也没有收到任何错误,而是说消息已发送。

mailtest.php: 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: 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 sendmail.ini

smtp_server=localhost
smtp_port=25

Use this sendmail program to use with an SMTP account like a gmail account. 使用此sendmail程序与gmail帐户等SMTP帐户一起使用。 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 这是主要的项目网站http://glob.com.au/sendmail/ ,这是一个快速的方法来自另一个答案的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. 这是我用于我的本地Windows环境,我只是找不到我学到的完整文章教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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