简体   繁体   English

确定电子邮件是否已成功发送

[英]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.

相关问题 使用ajax和php成功发送消息,但没有电子邮件 - Message successfully sent with ajax and php but no email PHPMailer 电子邮件发送成功但未收到 (EC2) - PHPMailer email sent successfully but not received (EC2) PHP 电子邮件已成功发送但 Gmail 未收到 - PHP email sent successfully but not received by Gmail Laravel-如何检查已成功发送给用户的重置密码电子邮件? - Laravel - How to check reset password email sent successfully to the user? WordPress用户已成功创建功能,但未发送“ SB欢迎电子邮件” - WordPress user functionally created successfully but 'SB Welcome Email' not sent 如何成功发送电子邮件或Codeigniter AJAX错误 - How to return if email is sent successfully or error in Codeigniter AJAX 电子邮件总是成功发送(Opencart v3.0.2.0) - Email always sent successfully (Opencart v3.0.2.0) 贝宝IPN成功发送 - paypal IPN successfully sent 使用Laravel 5,如何查看Mailgun电子邮件是否已成功发送? - Using Laravel 5, how can I find out if a Mailgun email was sent successfully? 从Bootstrap框架发送电子邮件我的错误是我收到消息是邮件发送成功,但是我没有收到任何邮件 - send email from bootstrap framework My error in this is i got a message is Mail sent successfully but i didn't receive any mail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM