从本地主机上的php发送电子邮件 [英] Sending email from php on localhost

查看:91
本文介绍了从本地主机上的php发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XAMPP与水星和雷鸟。当我通过Mercury发送消息时,该消息工作正常,我收到Thunderbird上的电子邮件。当我尝试使用PHP脚本时,它不会。



我确定它与php有关,但我无法找到解决方案,为什么不发送。



我也没有收到任何错误,它的消息是发送的。



mailtest.php:


  $ to =patrick @ localhost; 
$ subject =嗨;
$ body =text.PHP_EOL;
$ body。=此消息已发送.PHP_EOL;
$ headers =From:postmaster @ localhost;

if(mail($ to,$ subject,$ body,$ headers)){
echomessage sent!;
}
else {
echofailed;
}
?>

php.ini:

  [邮件功能] 

; XAMPP:如果要使用像Mercury这样的SMTP服务器,请注释出来
SMTP = localhost
smtp_port = 25

;我在Windows 7 64位
;仅适用于Win32
; http://php.net/sendmail-from
; sendmail_from = localhost

sendmail.ini

  smtp_server = localhost 
smtp_port = 25


解决方案

使用此sendmail程序与SMTP帐户一样使用,如Gmail帐户。以下是主要项目网站 http://glob.com.au/sendmail/ ,这里是从另一个答案中快速了解如何 https://stackoverflow.com/a/11210090/209067



这是我对我的本地Windows环境有什么用,我只是无法找到我学到的完整的文章教程。


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

解决方案

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.

这篇关于从本地主机上的php发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆