[英]PHP Confirmation Email after filling out Contact Form
我已經為我正在處理的項目創建了一個聯系頁面,但我無法讓它向用戶發送確認 email。 我在我的電子郵件頁面上定義了 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);
}
然后在聯系頁面上使用這些功能
echo $emailTest->sendEmail(); //send email to SMTP server
echo $emailTest->sendConfEmail(); //send confirmation email
我似乎無法弄清楚為什么一個工作而另一個不工作
請嘗試此代碼,您需要在sendEmail
成功后調用 function sendConfEmail
。 同樣從這里您需要修改 header。 但基於 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.