[英]Determine if a email was sent successfully
All, I have the standard mail code to send an email in PHP. 全部,我有标准的邮件代码,用PHP发送电子邮件。
$to = $resultset['email_address'];
$subject = "New client inquiry from Website.com";
$message = $email_message;
$from = $your_email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers,"-f $from");
The variables are created earlier in my code. 变量是在我的代码中创建的。 However what I want to check is to make sure that the mail function was executed successfully.
但是,我想检查的是确保邮件功能已成功执行。 With this code, how can I determine if sent the email and if it didn't echo out "failure"?
使用此代码,我如何确定是否发送了电子邮件,以及它是否没有回应“失败”?
Simply said: This is not possible with the PHP mail()
command. 简单地说:使用PHP
mail()
命令是不可能的。
the return value from mail()
just indicates, whether the mail was successfully handed over to the MTA, but not if it was sent. 来自
mail()
的返回值只表示邮件是否已成功切换到MTA,而不是是否已发送。 If eg your MTA is postfix, and the postfix service is stopped, mail()
will happily return true
, as queueing the mail to postfix worked. 如果您的MTA是后缀,并且后缀服务已停止,则
mail()
将很高兴返回true
,因为将邮件排队到postfix工作。 It will however never be sent, if postfix is not manually started (or even correctly configured). 但是,如果没有手动启动postfix(甚至正确配置),它将永远不会被发送。
If you really want to make sure, the mail has been sent, you need to talk to a MTA via sockets. 如果您确实要确保邮件已发送,则需要通过套接字与MTA通信。 There are frameworks for that.
有框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.