@carbanak01

Почему не отправляются письма на почту phpmailer?

При отправке формы в консоли выводится ошибка 500
const request = new XMLHttpRequest();
var form = document.getElementById('form_underHead');
form.querySelector('.btn').addEventListener('click', (e)=>{
	e.preventDefault();
	let data = new FormData(document.getElementById('form_underHead'));
	request.open("POST",'/wp-content/themes/autopodbor/sendMail.php');
	request.addEventListener("readystatechange",()=>{
		if(request.readyState === 4 && request.status === 200){
			console.log(data)
		}
	});
	request.send(data);
})

require_once 'wp-content/themes/autopodbor/PHPMailer.php';
require_once 'wp-content/themes/autopodbor/SMTP.php';
require_once 'wp-content/themes/autopodbor/Exception.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try{
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host = 'ssl://smtp.mail.ru';                // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'grisha.terteryan@mail.ru';                     // SMTP username
    $mail->Password   = 'GRISHA2003';                               // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
    $mail->Port = 465;                                     // TCP port to connect to

    //Recipients
    $mail->setFrom('grisha.terteryan@mail.ru');
    $mail->addAddress('hoxag61845@era7mail.com');     // Add a recipient
    //$mail->addAddress('ellen@example.com');             
    //$mail->addReplyTo('info@example.com', 'Information');
    //$mail->addCC('cc@example.com');
    //$mail->addBCC('bcc@example.com');

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
}catch (Exception $e) {
	echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

<form id="form_underHead">
                    <div class="row-input">
                        <input type="text" id="name" name="name" class="inputxt inputxt-telephone" placeholder="Введите ваше имя" style="width:350px">
                    </div>
                    <div class="row-input">
                        <input type="tel" id="telephone" name="telephone" class="inputxt inputxt-telephone" placeholder="Введите ваш телефон" style="width:350px">
                    </div>
                    <div class="row-input">
                        <input type="submit" class="btn btn-wan-auto" value="Отправить" style="width:200px">
                    </div>
                </form>
  • Вопрос задан
  • 217 просмотров
Пригласить эксперта
Ответы на вопрос 1
ThunderCat
@ThunderCat Куратор тега PHP
{PHP, MySql, HTML, JS, CSS} developer
ошибка 500

1) У вас отключен вывод ошибок и варнингов, все РЕАЛЬНЫЕ ошибки исполнения вы можете посмотреть в логах сервера.
2) На этапе разработки рекомендуется включить отображение всех ошибок и предупреждений, дабы не лазить по логоам на каждый чих.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы