设置发送电子邮件的 php.ini 参数是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15402887/
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
What are the php.ini parameters to set for sending email?
提问by pheromix
I want to send email from my PHP code, but I received warning messages. So what are the php.ini parameters to set ?
我想从我的 PHP 代码发送电子邮件,但我收到了警告消息。那么要设置的 php.ini 参数是什么?
回答by Jhonathan H.
To check/change your PHP mail configuration:
要检查/更改您的 PHP 邮件配置:
Open your php.ini file (if you don't know where this is, see below) Search for the line that reads [mail function] Add/change the details of your mail server. This could be a local mail server or the mail server of your ISP. Save/close the php.ini file Restart your web server
打开您的 php.ini 文件(如果您不知道它在哪里,请参见下文) 搜索显示为 [mail function] 添加/更改邮件服务器详细信息的行。这可能是本地邮件服务器或 ISP 的邮件服务器。保存/关闭 php.ini 文件重新启动您的 Web 服务器
An example of what the mail settings could look like when you first open the php.ini file:
首次打开 php.ini 文件时邮件设置的示例:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
Additional info is in echoing phpinfo()you can view your PHP configuration details. You can do this by creating a .php file with the following line on it: <?php phpinfo(); ?>. When you run this in your browser, you will see a full list of PHP configuration variables. Simply search for the lines that contain php.ini and sendmail_pathto see the values you need to use.
附加信息在呼应phpinfo()您可以查看您的 PHP 配置详细信息。您可以通过创建与它下面的线PHP文件做到这一点:<?php phpinfo(); ?>。当您在浏览器中运行它时,您将看到 PHP 配置变量的完整列表。只需搜索包含 php.ini 的行并sendmail_path查看您需要使用的值。
Another idea is you might use ini_set()to properly config your mail setting like this
另一个想法是您可以ini_set()像这样正确配置您的邮件设置
Add the following code to the top of your email script if your mail script continues to fail.
如果您的邮件脚本继续失败,请将以下代码添加到您的电子邮件脚本的顶部。
// Please specify your Mail Server - Example: mail.example.com.
ini_set("SMTP","mail.example.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', '[email protected]');

