我写了一小段用于发送邮件的PHP代码:
<?php
//define the receiver of the email
$to = 'rohaanthakare@gmail.com';
//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: webmaster@example.com\r\nReply-To: webmaster@example.com";
//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";
?>
Run Code Online (Sandbox Code Playgroud)
执行后我得到以下警告:
无法连接到"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 = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
Run Code Online (Sandbox Code Playgroud)
请建议我该怎么办?感谢所有提前.
您在该主机/端口组合上有 SMTP服务器吗?您可以通过执行以下操作来检查是否正在侦听
$ telnet localhost 25
Run Code Online (Sandbox Code Playgroud)
并看看是否telnet实际连接.