简体   繁体   English

PHP 填写联系表格后确认 Email

[英]PHP Confirmation Email after filling out Contact Form

I've created a contact page for a project im working on and im having trouble getting it to send a confirmation email to the user.我已经为我正在处理的项目创建了一个联系页面,但我无法让它向用户发送确认 email。 I have the function defined on my emailer page along with the code that sends the contact form to me我在我的电子邮件页面上定义了 function 以及将联系表发送给我的代码

public function sendEmail(){ //this will format and send an email to the smtp server
        $to = $this->getSenderEmail();
        $subject = $this->getSubject();
        $message = $this->getMessage();
        $headers = "From: <contact@tristonnearmyer.com >";
        $from = $this->getCustomerInfo();
        //it will use the php mail()
        return mail($to,$subject,$message,$from);
}
public function sendConfEmail(){
        $userEmail = $this->getRecipientEmail();
        $confSubject = "confirmation";
        $confMessage = "thank you";
        return mail($userEmail, $confSubject, $confMessage);
}

then the functions are used on the contact page然后在联系页面上使用这些功能

echo $emailTest->sendEmail(); //send email to SMTP server
echo $emailTest->sendConfEmail(); //send confirmation email

I can't seem to figure out why one is working while the other isn't我似乎无法弄清楚为什么一个工作而另一个不工作

Please try this code, you need to call the function sendConfEmail after sendEmail success.请尝试此代码,您需要在sendEmail成功后调用 function sendConfEmail Also from here you need to modify the header.同样从这里您需要修改 header。 But base on user3783243 commend better change to PHPMailer or use swift但基于 user3783243 建议更好地更改 PHPMailer 或使用 swift

public function sendEmail(){ //this will format and send an email to the smtp server
    $to = $this->getSenderEmail();
    $subject = $this->getSubject();
    $message = $this->getMessage();
    $from = $this->getCustomerInfo();
    $headers = 'From: '. $from . "\r\n" .
        'Reply-To: youremailhere@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();


    $sendMail =  mail($to,$subject,$message,$headers);

    if($sendMail){
        // Call the function send confirmation
        $this->sendConfEmail();
    }else{
        echo 'failed sent the email';
    }

}

public function sendConfEmail(){
    $userEmail = $this->getRecipientEmail();
    $confSubject = "confirmation";
    $confMessage = "thank you";
    $from = $this->getCustomerInfo();
    $headers = 'From: '. $from . "\r\n" .
        'Reply-To: youremailhere@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    return mail($userEmail, $confSubject, $confMessage,$headers);
}

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

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