无法在 windows 8 上使用 php 邮件功能发送电子邮件
Can't send email with php mail function on windows 8
我已经在 windows 8.
上安装了 wamp
出现错误:
Warning: mail() [function.mail]: Failed to connect to mailserver at
"localhost" port 25, verify your "SMTP" and "smtp_port" setting in
php.ini or use ini_set() in C:\wamp\www\mail.php on line 9
这里是简单的源代码:
<?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?
试试这个
配置此设置
在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
Important: comment following line if there is another sendmail_path
in the php.ini
: sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
Note: Tested and works fine in my Windows 8.1
可能的解决方案。 See this question
对我来说,在本地主机上配置邮件客户端非常困难。我也试了好几次。后来我转向其他解决方案。
您可以使用 SwiftMailer or PhpMailer with some configuration or you can try this tool 零配置。
附带说明一下,如果您将 windows PC 用于开发而非生产服务器,那么我建议您不要设置 sendmail 在 windows 中,只需使用这个方便的工具即可。
Test Mail Server Tool (Its Free)
它将模拟电子邮件服务器,一旦任何脚本尝试发送电子邮件,它就会拦截它并将其作为 .eml
文件为您打开,您可以在任何电子邮件中打开该文件 reader 喜欢 outlook 或 mail viewer(again its free).
现在设置此工具轻而易举,您稍后会感谢我节省的所有时间,因为您不必手动设置 sendmail,我必须提到的是 linux 机器。 ;)
我推荐 mercury(http://www.pmail.com/downloads_s3_t.htm - Mercury/32 用于 Win32 和 NetWare 系统的邮件传输系统 v4.74)。
这包含在 XAMPP 中,设置起来相当容易,您不需要配置或(滥用)使用电子邮件帐户。您可以在 mercury 邮件日志 window.
中看到整个 smtp 事务
在此处查找有关如何设置来自 php 的邮件的出色答案:PHP mail form doesn't complete sending e-mail
使用这个功能工具:
https://github.com/PHPMailer/PHPMailer
Mail() 非常难用,此函数允许您使用电子邮件服务器的 STMP 功能发送电子邮件。
在此处阅读文档:
https://github.com/PHPMailer/PHPMailer/blob/master/README.md
您需要与 php 一起使用电子邮件服务器。
https://www.hmailserver.com/
当您通过需要 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
您可以找到有关 PHPMailer 的更多信息 here。
您可以视频了解如何在 windows 上配置 SMTP here。
我已经在 windows 8.
上安装了 wamp出现错误:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\mail.php on line 9
这里是简单的源代码:
<?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?
试试这个
配置此设置
在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
Important: comment following line if there is another
sendmail_path
in thephp.ini
:sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
Note: Tested and works fine in my Windows 8.1
可能的解决方案。 See this question
对我来说,在本地主机上配置邮件客户端非常困难。我也试了好几次。后来我转向其他解决方案。
您可以使用 SwiftMailer or PhpMailer with some configuration or you can try this tool 零配置。
附带说明一下,如果您将 windows PC 用于开发而非生产服务器,那么我建议您不要设置 sendmail 在 windows 中,只需使用这个方便的工具即可。
Test Mail Server Tool (Its Free)
它将模拟电子邮件服务器,一旦任何脚本尝试发送电子邮件,它就会拦截它并将其作为 .eml
文件为您打开,您可以在任何电子邮件中打开该文件 reader 喜欢 outlook 或 mail viewer(again its free).
现在设置此工具轻而易举,您稍后会感谢我节省的所有时间,因为您不必手动设置 sendmail,我必须提到的是 linux 机器。 ;)
我推荐 mercury(http://www.pmail.com/downloads_s3_t.htm - Mercury/32 用于 Win32 和 NetWare 系统的邮件传输系统 v4.74)。
这包含在 XAMPP 中,设置起来相当容易,您不需要配置或(滥用)使用电子邮件帐户。您可以在 mercury 邮件日志 window.
中看到整个 smtp 事务在此处查找有关如何设置来自 php 的邮件的出色答案:PHP mail form doesn't complete sending e-mail
使用这个功能工具: https://github.com/PHPMailer/PHPMailer
Mail() 非常难用,此函数允许您使用电子邮件服务器的 STMP 功能发送电子邮件。
在此处阅读文档: https://github.com/PHPMailer/PHPMailer/blob/master/README.md
您需要与 php 一起使用电子邮件服务器。 https://www.hmailserver.com/
当您通过需要 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
您可以找到有关 PHPMailer 的更多信息 here。
您可以视频了解如何在 windows 上配置 SMTP here。