2011-01-22 51 views
1

我已经写了一小块的PHP代码发送邮件:无法连接到邮件服务器在PHP

<?php 
    //define the receiver of the email 
    $to = '[email protected]'; 
    //define the subject of the email 
    $subject = 'Hishob email'; 
    //define the message to be sent. Each line should be separated with \n 
    $message = "Hello World!\n\nThis is my first mail."; 
    //define the headers we want passed. Note that they are separated with \r\n 
    $headers = "From: [email protected]\r\nReply-To: [email protected]"; 
    //send the email 
    $mail_sent = mail($to, $subject, $message, $headers); 
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed"; 
    ?> 

执行它后,我得到了以下警告:

无法连接到邮件服务器在“localhost”端口25上,在php.ini中验证您的“SMTP”和“smtp_port”设置或在第11行的C:\ wamp \ www \ NewHishob \ PhpFiles \ send_mail.php中使用ini_set()
邮件失败

我正在使用WAMP服务器,并且有两个文件,INI-DIST和其他INI-RECOMENDED。哪一个很重要?

我也通过的php.ini-dist的文件不见了,用于SMTP它包含以下内容:

[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 = 

请建议我应该怎么办呢?感谢所有提前。

+1

WAMP不是服务器。 WAMP是Windows,Apache2 webserver,MySQL dbms和PHP脚本引擎组合的“代号”。 – 2011-01-22 15:19:14

回答

5

您是否该主机/端口组合上的SMTP服务器?你可以看一看是做听力有:

$ telnet localhost 25 

,看是否telnet实际连接。

0

此外,您不能保证邮件已发送,因为脚本不会等待邮件服务器继续。

0

忘掉这个,如果你在本地主机和Windows机器上,就不会工作。
改为使用PHPMailer
我已经设法通过GMail服务发送电子邮件(仅用于测试)。这真是简单...试试吧 PHPMailer