mym*_*and 17 php ubuntu sendmail
我正在使用Ubuntu.我使用以下命令在我的本地主机上安装了sendmail
sudo apt-get install sendmail
Run Code Online (Sandbox Code Playgroud)
现在我想使用以下php代码检查邮件是否来自我的localhost.
<?php
$to = "test@test.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Run Code Online (Sandbox Code Playgroud)
当我执行代码时,它需要很长时间,最后将邮件作为邮件发送回显.有没有可能解决这个问题?
小智 14
编辑文件/etc/hosts并确保第一行是以下内容:
127.0.0.1 localhost.localdomain localhost myhostname
编辑sendmail配置文件(/etc/mail/sendmail.cf在Ubuntu中)并取消注释line #O:
O HostsFile =/etc/hosts
重新启动计算机,或运行sudo service sendmail restart.
计算机现在应该启动得更快,并且该mail()功能应该几乎立即返回.
但是,除非您按照步骤5执行,否则实际上不会发送电子邮件.
-f每当使用mail函数时,您必须新使用sendmail 选项.
例如:
mail('recipient@somewhere.com', 'the subject', 'the message', null, '-fsender@somewhere.com');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16069 次 |
| 最近记录: |