php.ini, sendmail 配置使用php脚本发送邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20396449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:09:38  来源:igfitidea点击:

php.ini, sendmail configuration to send an email using a php script

phpemailsendmail

提问by kya

I need some help. I am trying to send an email from a php script. My environment comprises of the following:

我需要帮助。我正在尝试从 php 脚本发送电子邮件。我的环境包括以下内容:

Operating System: Windows 8

XAMPP version: 1.8.2

php version: 5.4.19

操作系统:Windows 8

XAMPP 版本:1.8.2

php 版本:5.4.19

I have the following php script:

我有以下 php 脚本:

<?php
mail('[email protected]','Helo','This is a test','From:[email protected]');
?>

The following configuration on send mail configuration file:

发送邮件配置文件如下配置:

smtp_server=smtp.gmail.com

; smtp port (normally 25)

smtp_port=465

auth_username=sugar.donkey+gmail.com
auth_password=[MYPASSWORDHERE]

The configurations on php.ini:

php.ini 上的配置:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury

; SMTP = smtp.gmail.com

; smtp_port = 465

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost

I dont get error when I run the php script, but I also dont seem to receive an email. Where am I going wrong ?

我在运行 php 脚本时没有收到错误消息,但我似乎也没有收到电子邮件。我哪里错了?

回答by Carlos Pliego

I am not sure what os you are running on your webserver, however;

但是,我不确定您在网络服务器上运行的是什么操作系统;

Most Linux installations have sendmail preinstalled, there is always a hassle of setting up SPF/PTR records, to ensure that the email sent by your PHP script is not flagged as spam. A SMTP client called MSMTP can be used to send emails using third-party SMTP servers, this can also be used by PHP's mail() in the place of sendmail.

大多数 Linux 安装都预装了 sendmail,设置 SPF/PTR 记录总是很麻烦,以确保您的 PHP 脚本发送的电子邮件不会被标记为垃圾邮件。一个名为 MSMTP 的 SMTP 客户端可用于使用第三方 SMTP 服务器发送电子邮件,这也可以由 PHP 的 mail() 代替 sendmail 使用。

I hope this helps

我希望这有帮助

https://www.digitalocean.com/community/articles/how-to-use-gmail-or-yahoo-with-php-mail-function

https://www.digitalocean.com/community/articles/how-to-use-gmail-or-yahoo-with-php-mail-function

Also for localhost testing, check this out. http://blogs.bigfish.tv/adam/2009/12/03/setup-a-testing-mail-server-using-php-on-mac-os-x/

同样对于本地主机测试,请查看此内容。 http://blogs.bigfish.tv/adam/2009/12/03/setup-a-testing-mail-server-using-php-on-mac-os-x/

回答by Raza Sheikh

Even I am trying to get this configuration work :)

即使我试图让这个配置工作:)

in your case i believe you need to comment out in php.ini

在你的情况下,我相信你需要在 php.ini 中注释掉

the configuration should be

配置应该是

; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury

SMTP = smtp.gmail.com

smtp_port = 465

; For Win32 only.

http://php.net/sendmail-from

sendmail_from = postmaster@localhost

Thank you

谢谢