2015-06-03 126 views
9

我已经安装WAMP在Windows 8不能在Windows使用PHP邮件功能发送邮件8

遇到错误:

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('[email protected]', 'My Subject', $message); 
?> 

我必须安装哪些软件才能通过Windows 8上的电子邮件发送电子邮件? sendmail,msmtp或ssmtp?

+0

你正在运行的IIS或Apache ...也许这将是有用的,http://www.neatcomponents.com/enable-SMTP-in-Windows-8 – chris85

+0

你运行一个邮件服务器?即时通讯猜测没有 –

+0

@ chris85,我想,Wamp服务器使用apache。没有邮件服务器。 – shibly

回答

11

试试这个

image

配置此设置

php.ini中

SMTP=smtp.gmail.com 
smtp_port=587 
sendmail_from = [email protected] 
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 
[email protected] 
auth_password=my-gmail-password 
[email protected] 

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

+0

它不起作用 – shibly

+0

@明显地读这个。 http://stackoverflow.com/questions/30702003/how-to-send-email-from-localhost-using-codeigniter/30703350#30703350 –

+1

从属性改变sendmail.exe的兼容模式后它正在工作。对于Windows 7或更高版本,您必须从属性中将sendmail.exe的兼容模式更改为“Windows xp Service Pack 3”。 http://stackoverflow.com/questions/21337859/sendmail-wamp-php,请参阅http://glob.com.au/sendmail/ – shibly

4

可能的解决方案。 See this question

对我来说,在本地主机上配置邮件客户端是相当困难的。我也尝试了很多次。后来我转向其他解决方案。

您可以使用SwiftMailerPhpMailer进行一些配置,或者您可以尝试使用零配置的this tool

+0

中的“windows 8+上运行的问题”如果您放弃第一行,恕我直言,唯一正确的答案是:_不使用PHP的'mail()'函数。 –

+0

@ JasperN.Brouwer是的,这里也一样。不要以为使用mail()函数是个好主意。但是如果提问者可以从那里得到一些想法,那么就包括了这个链接。 – chanafdo

1

在一个侧面说明,如果你使用的是Windows PC上的发展,而不是作为一个生产服务器,那么我建议你不要打扰设立的sendmail窗口,只是用这个方便的工具。

Test Mail Server Tool (Its Free)

它会模仿电子邮件服务器,一旦任何脚本试图发送电子邮件,它会拦截它,打开它你作为一个.eml文件,你可以在任何电子邮件阅读器,如Outlook打开或mail viewer(again its free)

现在设置这个工具只是一个轻松的工具,你将在以后为你保存的所有时间感谢我,而不必手动设置sendmail,我必须提到它是在Linux机器上。 ;)

1

我建议汞(http://www.pmail.com/downloads_s3_t.htm - Mercury/32邮件传输系统的Win32和NetWare系统版本4.74)。

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

0

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

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

//ini settings 
ini_set("SMTP", "aspmx.l.google.com"); 
ini_set("sendmail_from", "[email protected]"); 

$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

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