【发布时间】:2011-01-22 15:17:50
【问题描述】:
我写了一小段用于发送邮件的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";
?>
执行后我收到以下警告:
无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或在 C:\wamp\www\NewHishob\PhpFiles\send_mail.php 中使用 ini_set()第 11 行
邮件失败
我正在使用 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 =
请建议我应该怎么做?在此先感谢大家。
【问题讨论】:
-
WAMP 不是服务器。 WAMP 是 Windows、Apache2 网络服务器、MySQL dbms 和 PHP 脚本引擎的组合的“代号”。
-
请纠正格式。侧边栏上有说明。
-
这些“[CODE]”是什么废话?