Answer the question
In order to leave comments, you need to log in
Why don't emails get through even though PHPMailer doesn't throw an error?
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->setLanguage('ru', 'phpmailer/language');
$mail->isHTML(true);
// От кого письмо
$mail->setFrom('[email protected]','Тема письма');
// Кому отправитель
$mail->addAddress('[email protected]','Тема письма');
// Тема письма
$mail->Subject = 'Привет, письмо с сайта';
$body = '<h1>Письмо!</h1>';
if(trim(!empty($_POST['name']))){
$body.='<p><strong>Имя:</strong> '.$_POST['name'].'</p>';
}
if(trim(!empty($_POST['email']))){
$body.='<p><strong>Email:</strong> '.$_POST['email'].'</p>';
}
if(trim(!empty($_POST['phone']))){
$body.='<p><strong>Phone:</strong> '.$_POST['phone'].'</p>';
}
$mail->Body = $body;
if (!$mail->send()){
$message = 'Ошибка';
} else {
$message = 'Данные отправлены';
}
$response = ['message' => $message];
header('Content-type: application/json');
echo json_encode($response);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question