PHP Подтверждение по электронной почте после заполнения контактной формы - PullRequest
0 голосов
/ 03 мая 2020

Я создал страницу контактов для проекта, над которым я сейчас работаю, и у меня возникают проблемы с его отправкой по электронной почте пользователю подтверждения. У меня есть функция, определенная на моей странице электронной почты вместе с кодом, который отправляет мне контактную форму

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

Я могу ' кажется, не понять, почему один работает, а другой нет

1 Ответ

0 голосов
/ 03 мая 2020

Пожалуйста, попробуйте этот код, вам нужно вызвать функцию sendConfEmail после sendEmail успеха. Также из здесь необходимо изменить заголовок. Но основываясь на 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);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...