На локалке скрипт работает (без вп), начал переносить на сайт, выдает ошибку, по дебагу выдал это (Порты менял)
2019-12-13 16:24:21 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP t27sm5175832ljd.26 - gsmtp
2019-12-13 16:24:21 CLIENT -> SERVER: EHLO a0368236.xsph.ru
2019-12-13 16:24:21 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a0a:2b42:41:5b75::]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2019-12-13 16:24:21 CLIENT -> SERVER: STARTTLS
2019-12-13 16:24:21 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2019-12-13 16:24:21 CLIENT -> SERVER: EHLO a0368236.xsph.ru
2019-12-13 16:24:21 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a0a:2b42:41:5b75::]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2019-12-13 16:24:21 CLIENT -> SERVER: AUTH LOGIN
2019-12-13 16:24:21 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2019-12-13 16:24:21 CLIENT -> SERVER: c2hnLml2YW45N0BnbWFpbC5jb20=
2019-12-13 16:24:21 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2019-12-13 16:24:21 CLIENT -> SERVER: M1owMElwTWIjUSVnX1dl
2019-12-13 16:24:21 SERVER -> CLIENT: 534-5.7.14 534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 t27sm5175832ljd.26 - gsmtp
2019-12-13 16:24:21 SMTP ERROR: Password command failed: 534-5.7.14 534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 t27sm5175832ljd.26 - gsmtp
SMTP Error: Could not authenticate.
2019-12-13 16:24:21 CLIENT -> SERVER: QUIT
2019-12-13 16:24:21 SERVER -> CLIENT: 221 2.0.0 closing connection t27sm5175832ljd.26 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl...
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl...
js
$(function(){
$('#ajax_form').submit(function(){
var data = $('#ajax_form').serialize();
$.ajax({
url: '/wp-content/themes/electric/mail.php',
type: 'POST',
data: data,
success: function(res) {
}
})
return false
})
});
Код php
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'shg.ivan97@gmail.com';
$mail->Password = 'tyt_moi_password';
$mail->Port = 587;
$mail->SMTPDebug = 2;
$mail->From = 'shg.ivan97@gmail.com';
$mail->FromName = 'DvaBro';
$mail->addAddress('shg.ivan97@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'Новая заявка с сайта DvaBro';
$mail->Body = "Имя: {$_POST['name']}<br>Фамилия: {$_POST['surname']}";
$mail->AltBody = Имя: {$_POST['name']}\r\nФамилия: {$_POST['surname']};
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
расположение файлов:
...
/js/main.js
-mail.php
-class.phpmailer.php
-class.phpmaileroauth.php
-class.phpmaileroauthgoogle.php
-class.pop3.php
-class.smtp.php
-PHPMailerAutoload.php
-index.php