我最近转移了我的服务器,发现默认的 PHP 邮件功能在以前的服务器中不起作用。我通过编写简单的邮件功能对其进行了测试
$mailto="[email protected]"; //Enter recipient email address here
$subject = "Test Email";
$from="[email protected]"; //Your valid email address here
$message_body = "This is a test email from Webmaster.";
$mail = mail($mailto,$subject,$message_body,"From:".$from);
var_dump($mail);
if($mail) {
echo "Your email has been sent successfully";
} else {
echo "not sent";
}
上面的代码返回错误值。我用谷歌搜索了一下。检查了我的 PHP.ini。它也被设置为谷歌链接中提到的解决方案。
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from [email protected]
; For Unix only. You may supply arguments as well
(default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "/usr/sbin/sendmail -t -i"
我不知道我缺少什么。
它返回FALSE
,这意味着您的邮件配置有问题。您需要检查邮件日志以查看是否有任何错误。关键是 php 可能正在发送邮件,您的服务器可能正在发送邮件,并且可能会在此过程中过滤垃圾邮件。
<?php
mail('[email protected]', 'the subject', 'the message', null, '[email protected]');
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句