简体   繁体   English

php联系表格,是否可以检查是否已收到自动电子邮件?

[英]php contact form, is it possible to check if an automated email has been received?

I have been digging around to look for suggestions on how to ensure an email address that has been inputted in a web form is valid or not. 我一直在四处寻找有关如何确保已在Web表单中输入的电子邮件地址有效的建议。 It seems like the best solution is to send an automated email to the email address the user has submitted, if they receive it then great if not its obviously not valid. 似乎最好的解决方案是将自动电子邮件发送到用户已提交的电子邮件地址,如果他们收到了该电子邮件地址,则该电子邮件地址显然无效,那么效果很好。

what i want to do is have the user fill in the contact form, when they submit the form it checks all validation and then sends an automated email to the users email address, then depending on whether the email was successfully received send the original query to my email. 我想要做的是让用户填写联系表格,当他们提交表格时,它会检查所有验证,然后向用户的电子邮件地址发送自动电子邮件,然后根据是否成功接收到电子邮件,将原始查询发送到我的电子邮件。

I can get the automated email sending ok but is there a way to get php to return a email received confirmation so that i can process the rest of my script? 我可以自动发送电子邮件,但有没有办法让php返回收到的电子邮件确认,以便我可以处理脚本的其余部分?

here is my code 这是我的代码

<?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>";
    }   

But I'm unsure how to tell if the auto response email was delivered or not? 但是我不确定如何判断自动回复电子邮件是否已发送?

any help is greatly appreciated 任何帮助是极大的赞赏

An automatic and instant delivery confirmation is not possible, so if you're thinking about waiting for that confirmation for your script to perform the second part of the signup process, you need to rethink your strategy. 无法实现自动即时交付确认,因此,如果您正在考虑等待该确认以等待脚本执行注册过程的第二部分,则需要重新考虑您的策略。

Also, keep in mind that a valid email doesn't necessarily mean that the email belongs to the person signing up. 另外,请记住,有效的电子邮件并不一定意味着该电子邮件属于注册人。 I could in theory sign up to your site using an email of someone I know and be OK just because the email exists. 从理论上讲,我可以使用我认识的某人的电子邮件来注册您的站点,并且可以,因为该电子邮件存在而可以。

If you need email validation, you should consider sending an automated email with a unique disposable link which the user clicks to complete the process or containing a unique code which the user must enter in a confirmation step. 如果您需要电子邮件验证,则应考虑发送带有唯一的一次性链接的自动电子邮件,用户单击该链接即可完成该过程,或者包含一个唯一的代码,用户必须在确认步骤中输入该代码。

My suggestion would be to include a link in the email pointing to your site (ie, yoursite.com/verification/random_unique_string) 我的建议是在指向您网站的电子邮件中包含一个链接(即yoursite.com/verification/random_unique_string)

The random_unique_string may be anything as long as it's not reversible by a malicious user. 只要恶意用户不可逆, random_unique_string可以是任何东西。 For inatance, it could be a hash of the recipient email, date sent, random salt, etc which is unique and when clicked, leads to the finalization of the sign up process 对于Atatance,这可能是收件人电子邮件的哈希,发送日期,随机盐等,这是唯一的,当单击时,会导致注册过程完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM