A
A
Artyom2020-10-29 20:41:17
PHPMailer
Artyom, 2020-10-29 20:41:17

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);

?>

does not give an error, but the letter does not reach?
Tried two mail also does not send

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question