php 使用 WAMP 发送电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1993070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:34:11  来源:igfitidea点击:

Sending emails with WAMP

phpemail

提问by Jorm

I use the latest WAMP and I get this when I try to send emails:

我使用最新的 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

Message delivery failed...

消息传递失败...

The message:

消息:

$to = "[email protected]";
$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>");
 }

Do you need do download a "mailserver" also?

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

Please help.

请帮忙。

回答by Josh

This works for me and should work for you: Use Fake Sendmailand a webhost mail server (i.e. - Godaddy, 1and1, etc.).

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

1.) Download the sendmail zip and extract it to C:\Wamp\bin\sendmail (for purposes of this example).

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

2.) Edit C:\wamp\bin\sendmail\sendmail.ini and set the following to your mail server's requirements (mine are below):

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

smtp_server=mail.yourdomain.com
smtp_port=26
smtp_ssl=none
;default_domain=yourdomain.com
[email protected]
auth_password=smtppassword
;pop3_server=
;pop3_username=
;pop3_password=
;force_sender=
;force_recipient=

3.) Set the path of sendmail.exe in your php.ini file.

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.) Restart Wampserver.

4.) 重新启动 Wampserver。

You might have success using Gmail, but there are a few extra tweaks to make it work. I prefer using the mail server of the webhost where I upload my code.

您可能会成功使用 Gmail,但需要进行一些额外的调整才能使其发挥作用。我更喜欢使用我上传代码的网络主机的邮件服务器。

回答by Tatu Ulmanen

You are not running an smtp server on your machine, but you don't have to. Just set SMTP to a open smtp server for example:

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

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

Take a look at your ISP's home page or http://www.e-eeasy.com/SMTPServerList.aspxfor list of SMTP servers.

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

If you have a desktop mail program, you can use the same address as you use for outgoing mail.

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

回答by Tony The Lion

I think your mail server (SMTP) outgoing mail server is not configured in your php.ini file.

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

Have a look at this:

看看这个:

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

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

Also hotmail doesn't allow you to use their mailservers. You should use yahoo or gmail.

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

回答by John M.

Are you sure these servers have a mail program installed on them? If not, that's your problem. For example, XAMPP comes with a mail program called Mercury which you must start before you can send mail through the server.

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

回答by sandrows

Follow this article, it works if you have a gmail account. or at least any email account in which you know the server, port and this stuff.

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

Send Email From localhost

从本地主机发送电子邮件

回答by T.Todua

here is another solution - WAMP send Mail using SMTP localhost

这是另一个解决方案 - WAMP 使用 SMTP localhost 发送邮件


KEEP IN MIND, everytime, after You change php.ini,


请记住,每次更改 php.ini 后,

you must restart wamp (! ! !)

你必须重新启动wamp(!!!)

p.s. in php.ini, i have used:

ps 在 php.ini 中,我使用过:

SMTP = localhost 
smtp_port = 25 
sendmail_from = [email protected]

or if oyu cant edit php.ini, try to insert these lines in your php script.

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

ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
ini_set("sendmail_from", "[email protected]");