【问题标题】:Can't send email with php mail function on windows 8无法在 Windows 8 上使用 php 邮件功能发送电子邮件
【发布时间】:2015-08-17 02:09:42
【问题描述】:

我已经在 Windows 8 上安装了 wamp。

出现错误:

警告:mail() [function.mail]:无法连接到邮件服务器 “localhost”端口 25,验证您的“SMTP”和“smtp_port”设置 php.ini 或在第 9 行的 C:\wamp\www\mail.php 中使用 ini_set()

这里是简单的源代码:

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");

// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>

我必须在 Windows 8 上通过 php 安装哪些软件才能通过电子邮件发送电子邮件? sendmail、msmtp 还是 ssmtp?

【问题讨论】:

  • 你是在运行 IIS 还是 Apache...也许这会很有用,neatcomponents.com/enable-SMTP-in-Windows-8
  • 您在运行邮件服务器吗?我猜没有
  • @chris85,我认为,Wamp 服务器使用 apache。没有邮件服务器。
  • 发送电子邮件你需要一个,但是从 wamp mot 人们使用另一个,例如你的 ISP 或 gmail。如果您打算托管它,最好现在跳过这一步并使用您的网络主机邮件服务器。 stackoverflow.com/questions/3412055/…
  • @Dagon,要安装哪个邮件服务器?

标签: php windows email xampp


【解决方案1】:

试试这个

配置此设置

php.ini

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini 中:

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

重要提示:如果php.ini 中有另一个sendmail_path,请在以下行注释:sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

注意:在我的 Windows 8.1 中测试并正常工作

【讨论】:

  • 从属性中更改sendmail.exe的兼容模式后就可以使用了。对于 windows 7 或更高版本,您必须从属性中将 sendmail.exe 的兼容模式更改为“Windows xp service pack 3”。 stackoverflow.com/questions/21337859/sendmail-wamp-php,请参阅glob.com.au/sendmail中的“在 Windows 8+ 上运行的问题”@
  • 使用最新的sendmail for Windows 并遵循基本安装说明,确保从php.ini 文件中删除smtp 配置,因为如果您已经在你的sendmail.ini 文件。此外,如果我使用 sendmail_path = "C:\Program Files (x86)\sendmail\sendmail.exe" 而不使用 -t 参数,我只能让它工作。如果有人好奇,我在 Windows 10 上使用 IIS。
【解决方案2】:

可能的解决方案。 See this question

对我来说,在 localhost 上配置邮件客户端非常困难。我也试了好几次。后来我转向其他解决方案。

您可以使用 SwiftMailerPhpMailer 进行一些配置,也可以尝试使用 this tool 进行零配置。

【讨论】:

  • 如果你放弃第一行,恕我直言,你有唯一正确的答案,即:不要使用 PHP 的 mail() 函数。
  • @JasperN.Brouwer 是的,这里也一样。不要认为使用mail() 函数是个好主意。但如果提问者可以从那里得到一些想法,请包含该链接。
【解决方案3】:

附带说明,如果您使用 Windows PC 进行开发而不是作为生产服务器,那么我建议您不要费心在 windowssendmail /em>,请使用这个方便的工具。

Test Mail Server Tool (Its Free)

它将模拟电子邮件服务器,一旦任何脚本尝试发送电子邮件,它就会拦截它并以.eml 文件的形式为您打开,您可以在任何电子邮件阅读器(如 Outlook 或 mail viewer(again its free))中打开该文件.

现在设置这个工具只是一件轻而易举的事,稍后你会感谢我为你节省的所有时间,因为不必手动设置 sendmail,我必须提到它是在 linux 机器上。 ;)

【讨论】:

    【解决方案4】:

    我推荐使用 Mercury(http://www.pmail.com/downloads_s3_t.htm - Mercury/32 Mail Transport System for Win32 and NetWare Systems v4.74)。

    这包含在 XAMPP 中,设置起来相当容易,您无需配置或(ab)使用电子邮件帐户。您可以在水银邮件日志窗口中看到整个 smtp 事务。

    【讨论】:

      【解决方案5】:

      在此处查看有关如何从 php 设置邮件的绝佳答案:PHP mail form doesn't complete sending e-mail

      【讨论】:

        【解决方案6】:

        使用此功能工具: https://github.com/PHPMailer/PHPMailer

        Mail() 非常难用,这个函数允许你使用电子邮件服务器的 STMP 函数来发送电子邮件。

        在此处阅读文档: https://github.com/PHPMailer/PHPMailer/blob/master/README.md

        【讨论】:

          【解决方案7】:

          您需要将电子邮件服务器与 php 一起使用。 https://www.hmailserver.com/

          【讨论】:

            【解决方案8】:

            当您通过需要 SMTP 的服务器使用电子邮件发件人功能时 身份验证,您必须指定它。并设置主机、用户名和 密码(如果不是默认密码,也可能是端口 - 25)。

            例如,我通常使用与此类似的设置的 PHPMailer:

            //ini settings
            ini_set("SMTP", "aspmx.l.google.com");
            ini_set("sendmail_from", "YOURMAIL@gmail.com");
            
            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->CharSet = 'UTF-8';
            
            $mail->Host       = "mail.example.com"; // SMTP server example
            $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
            $mail->Username   = "username"; //Your SMTP account username example
            $mail->Password   = "password";        //Your SMTP account password example
            

            您可以在here找到更多关于PHPMailer的信息。

            您可以通过视频了解如何在 wondows here 上配置 SMTP。

            【讨论】:

              猜你喜欢
              • 2014-09-05
              • 2014-05-23
              • 2012-12-12
              • 1970-01-01
              • 1970-01-01
              • 2012-02-04
              • 2021-05-10
              • 1970-01-01
              相关资源
              最近更新 更多