I
I
Ivan Shulga2019-12-13 19:37:00
PHPMailer
Ivan Shulga, 2019-12-13 19:37:00

How to upload PHPMAILER to Wordpress?

The script works on local (without vp), started transferring to the site, gives an error, by debug it gave this (Changed ports)


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
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
-> 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
VXNlcm2hb2hb5 :24:21 CLIENT -> SERVER: c2hnLml2YW45N0BnbWFpbC5jb20=
2019-12-13 16:24:21 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2019-12-13 16:24:21 CLIENT -> SERVER:
M1owMElwTWIjUSVnX1dl :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/78754t27sm5175832ljd.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 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 code
<?php 

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();         
$mail->Host = 'smtp.gmail.com';  
$mail->SMTPAuth = true;                             
$mail->Username = '[email protected]';           
$mail->Password = 'tyt_moi_password';                      
$mail->Port = 587;                                  
$mail->SMTPDebug = 2;
$mail->From = '[email protected]';
$mail->FromName = 'DvaBro';
$mail->addAddress('[email protected]');               

$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';
}
?>

files location:
...
/js/main.js
-mail.php
-class.phpmailer.php
-class.phpmaileroauth.php
-class.phpmaileroauthgoogle.php
-class.pop3.php
-class.smtp.php
-PHPMailerAutoload.php
-index.php

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Mavlikhanov, 2019-12-13
@ZamarShoo

It seems like WordPress already has a PHPMailer class and it works in wp_mail(), so you get an error

A
Alexander, 2020-11-21
@avenn2015

In WP, you need to send ajax requests differently. by google ajax in wordpress, everything is painted on the cam, I'm wondering why neither wp_mail nor phpmailer works for me, from local, letters do not stupidly come but are sent

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question