使用WAMP发送电子邮件

时间:2010-01-02 22:18:02

标签: php email

我使用最新的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\main\createaccount.php on line 8

邮件传递失败......

消息:

$to = "xxx@hotmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }

你还需要下载“邮件服务器”吗?

请帮忙。

6 个答案:

答案 0 :(得分:15)

这对我有用,应该对你有用:使用Fake Sendmail和一个虚拟主机邮件服务器(即 - Godaddy,1and1等)。

1。)下载sendmail zip并将其解压缩到C:\ Wamp \ bin \ sendmail(就此示例而言)。

2.)编辑C:\ wamp \ bin \ sendmail \ sendmail.ini并将以下内容设置为您的邮件服务器的要求(我的下面是):

smtp_server=mail.yourdomain.com
smtp_port=26
smtp_ssl=none
;default_domain=yourdomain.com
auth_username=smtpuser@yourdomain.com
auth_password=smtppassword
;pop3_server=
;pop3_username=
;pop3_password=
;force_sender=
;force_recipient=

3.。)在php.ini文件中设置sendmail.exe的路径。

[mail function]
; For Win32 only.
SMTP =

; For Win32 only.
sendmail_from =

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\wamp\bin\sendmail\sendmail.exe -t"

4.)重启Wampserver。

您可能使用Gmail取得了成功,但还有一些额外的调整可以让它发挥作用。我更喜欢使用我上传代码的webhost的邮件服务器。

答案 1 :(得分:1)

您没有在计算机上运行smtp服务器,但您不必这样做。只需将SMTP设置为打开的smtp服务器,例如:

ini_set('SMTP', 'smtp.yourisp.com');

查看ISP的主页或http://www.e-eeasy.com/SMTPServerList.aspx以获取SMTP服务器列表。

如果您有桌面邮件程序,则可以使用与发送邮件相同的地址。

答案 2 :(得分:0)

我认为您的邮件服务器(SMTP)外发邮件服务器未在您的php.ini文件中配置。

看看这个:

http://email.about.com/od/emailprogrammingtips/qt/Configure_PHP_to_Use_a_Remote_SMTP_Server_for_Sending_Mail.htm

此外,hotmail不允许您使用他们的邮件服务器。你应该使用雅虎或gmail。

答案 3 :(得分:0)

您确定这些服务器上安装了邮件程序吗?如果没有,那就是你的问题。例如,XAMPP附带了一个名为Mercury的邮件程序,您必须在通过服务器发送邮件之前启动它。

答案 4 :(得分:0)

按照这篇文章,如果您有一个Gmail帐户,它就有效。 或者至少你知道服务器,端口和这些东西的任何电子邮件帐户。

Send Email From localhost

答案 5 :(得分:-1)

这是另一种解决方案 - WAMP send Mail using SMTP localhost


在更改php.ini后,每次都要保持心情,

你必须重启wamp(!!!)

P.S。在php.ini中,我使用过:

SMTP = localhost 
smtp_port = 25 
sendmail_from = your_user@gmail.com

或者如果oyu无法编辑php.ini,请尝试在php脚本中插入这些行。

ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
ini_set("sendmail_from", "your_user@gmail.com");