在本地主机中发送邮件需要很长时间
我正在使用 Ubuntu。我使用以下命令在本地主机中安装了 sendmail
sudo apt-get install sendmail
现在我想使用以下 php 代码检查邮件是否来自我的本地主机。
<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
当我执行代码时,需要很长时间才能最终将消息回显为“邮件已发送”。 有没有可能解决这个问题?
I am using Ubuntu.I installed sendmail in my local host using the following command
sudo apt-get install sendmail
Now I would like to check whether mail goes from my localhost using following php code.
<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
When i execute the code, It takes very long time and finally echo the message as Mail Sent.
Is there any possibilities to fix this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
编辑文件
/etc/hosts
并确保第一行如下:编辑
sendmail
配置文件(在 Ubuntu 中为/etc/mail/sendmail.cf
)并取消注释行 #O:
重新启动计算机,或运行
sudo service sendmail restart
。计算机现在应该启动得更快,并且
mail()
函数应该几乎立即返回。但是,除非您按照步骤 5 操作,否则电子邮件实际上不会发送。
每当使用邮件功能时,您都必须重新使用 sendmail
-f
选项。例如:
Edit the file
/etc/hosts
and make sure the first line is the following:Edit the
sendmail
configuration file (/etc/mail/sendmail.cf
in Ubuntu) and Uncomment theline #O
:Restart the computer, or run
sudo service sendmail restart
.The computer should boot up much faster now and the
mail()
function should return almost immediately.HOWEVER, the emails won't actually be sent unless you follow step 5.
You must new use the sendmail
-f
option whenever using the mail function.For example:
我知道这个问题已经得到解答,但我发布此问题是希望它可以帮助其他人寻找此问题的不同解决方案。
对我来说,我只需要将服务器的完全限定域名 (FQDN) 放入
/etc/mailname
中。例如:server.example.com
。重新启动 Sendmail 以应用更改。
$ sudo 服务 sendmail 重新启动
I know this question has already been answered, but I'm posting this in the hope it may help someone else looking for a different solution to this issue.
For me, I just needed to put my server's Fully Qualified Domain Name (FQDN) into
/etc/mailname
. For example:server.example.com
.Restart Sendmail to apply the changes.
$ sudo service sendmail restart
这个答案帮助我https://serverfault.com/a/221894/186680
安装了Postfix和sendmail。删除了 sendmail
Yum 删除了 sendmail
This answer helped me https://serverfault.com/a/221894/186680
Postfix and sendmail where installed. Removed sendmail
Yum remove sendmail
延迟通常表示 DNS 超时。您的计算机是否配置了正确的 DNS 条目?我会尝试在命令行上使用邮件进行测试,因为这可以隔离问题。
The delay is usually indicating a DNS time-out. Is your machine configured with proper DNS entries? I would try doing a test using mail on the command line as this would isolate the issue.
除非您非常了解 Sendmail,否则最好安装其他 MTA。另一个答案中已经建议了 ssmtpd ;一个常见的选择是 Postfix。
Unless you know Sendmail well, you are probably bettter off installing some other MTA.
ssmtpd
was already suggested in another answer; a common choice is Posfix.