我一直在四处寻找有关如何确保以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>";
}
但是我不确定如何确定自动回复电子邮件是否已发送?
非常感谢您的帮助
答案 0 :(得分:5)
不可能实现自动即时交付确认,因此,如果您正在考虑等待该确认以等待脚本执行注册过程的第二部分,则需要重新考虑您的策略。
此外,请记住,有效的电子邮件并不一定意味着该电子邮件属于注册人。从理论上讲,我可以使用我认识的人的电子邮件来注册您的网站,并且可以,因为该电子邮件存在而可以。
如果您需要电子邮件验证,则应考虑发送带有唯一的一次性链接的自动电子邮件,用户单击该链接即可完成该过程,或者包含唯一的代码,用户必须在确认步骤中输入该代码。
我的建议是在电子邮件中包含指向您网站的链接(即yoursite.com/verification/random_unique_string)
random_unique_string
可以是任何东西,只要它不能被恶意用户逆转即可。对于Atatance,这可能是收件人电子邮件的哈希,发送日期,随机盐等,它们是唯一的,并且在单击时会导致完成注册过程