8

我想从我的 PHP 代码发送电子邮件,但我收到了警告消息。那么要设置的 php.ini 参数是什么?

4

1 回答 1

13

检查/更改您的 PHP 邮件配置:

打开您的 php.ini 文件(如果您不知道它在哪里,请参见下文) 搜索读取 [mail function] 添加/更改邮件服务器的详细信息的行。这可以是本地邮件服务器或 ISP 的邮件服务器。保存/关闭 php.ini 文件 重新启动您的网络服务器

首次打开 php.ini 文件时邮件设置的示例:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

附加信息在回显中,phpinfo()您可以查看您的 PHP 配置详细信息。您可以通过创建一个包含以下行的 .php 文件来做到这一点:<?php phpinfo(); ?>. 当您在浏览器中运行它时,您将看到 PHP 配置变量的完整列表。只需搜索包含 php.ini 的行并sendmail_path查看您需要使用的值。

另一个想法是您可以ini_set()像这样正确配置您的邮件设置

如果您的邮件脚本继续失败,请将以下代码添加到您的电子邮件脚本的顶部。

// 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', 'example@YourDomain.com');
于 2013-03-14T06:53:17.240 回答