【发布时间】:2019-05-23 20:16:47
【问题描述】:
我一直在四处寻找有关如何确保在 Web 表单中输入的电子邮件地址有效或无效的建议。似乎最好的解决方案是向用户提交的电子邮件地址发送一封自动电子邮件,如果他们收到它,那么如果不是它显然无效,那就太好了。
我想做的是让用户填写联系表格,当他们提交表格时,它会检查所有验证,然后向用户的电子邮件地址发送一封自动电子邮件,然后根据是否成功收到电子邮件发送原始查询到我的电子邮件。
我可以让自动电子邮件发送正常,但有没有办法让 php 返回收到的电子邮件确认,以便我可以处理我的脚本的其余部分?
这是我的代码
<?php
// if user has submitted the form and there are no errors
if(($_SERVER["REQUEST_METHOD"] == "POST") && !$nameErr && !$emailErr && !$phoneErr && !$messageErr && !$botErr && !$pointsErr)
{
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Set the hostname of the mail server
$mail->Host = 'mailout.one.com';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = 'USERNAME';
//Password to use for SMTP authentication
$mail->Password = 'PASSWORD';
//Set who the message is to be sent from
$mail->setFrom($from, $name);
//Set an alternative reply-to address
$mail->addReplyTo($email, $name);
//Set who the message is to be sent to
$mail->addAddress($from, 'PERSON');
// To send automated reply mail
$autoemail = new PHPMailer();
$autoemail->From = $from;
$autoemail->FromName = "PERSON";
$autoemail->AddAddress($email, $name);
$autoemail->Subject = "Autorepsonse: We received your submission";
$autoemail->Body = "We received your submission. We will contact you soon ...";
$autoemail->Send();
if(!$autoemail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
//CHECK AUTOMATED EMAIL HAS BEEN RECEIVED BY THE USER THEN SEND THEIR ENQUIRY EMAIL
//Set the subject line
#$mail->Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
#$mail->Body = $message."<p><strong>Club Enquiry Relates To: </strong>".$club."</p><p><strong>Client Details</strong></p>Name: ".$name."<br/>Email: ".$email."<br />Tel No: ".$phone."<p><strong>Extras</strong></p>How Did you find our website? ".$hearsay."<br/ >Spam Score: ".$points." out of ".$maxPoints."<br />IP Address: ".$_SERVER['REMOTE_ADDR'];
//Replace the plain text body with one created manually
#$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
#$mail->addAttachment('images/phpmailer_mini.png');
echo"<h2>Thank You!!!</h2>";
echo "<p>Your message has been sent successfully, we aim to respond within a couple of days. Please check your Junk/Span folder incase it ends up there.</p>";
}
但我不确定如何判断自动回复电子邮件是否已送达?
非常感谢任何帮助
【问题讨论】:
-
“有没有办法让 php 返回收到的电子邮件确认,以便我可以处理我的脚本的其余部分?” - 只有当他们有一个链接到单击它会在 your 端进行某种类型的验证,无论是写入文件还是数据库。
-
“但我不确定如何判断自动回复电子邮件是否已送达?” -
if(condition){...},您现在似乎正在这样做。 -
感谢@FunkFortyNiner 我认为可能是这种情况,但希望有一个更快更简单的过程:(
-
欢迎。嗯,它“有点”简单。就像我说的那样,您可以让他们点击链接,作为带有参数的 METHOD 发送,然后如果他们点击它,然后将通过相同的方法检索它并检查它是否设置/不为空。到文件和/或数据库。设置任何一种方法都不会花费太多时间。恐怕没有什么“又快又脏”。
-
你也可以看看How to check if an email address is real or valid using PHP。它可能或可能不适合你。考虑到系统/服务器支持(或不支持)什么,现在很难检查真实的电子邮件。
标签: php phpmailer email-validation