A
A
AveConstantis2021-06-02 19:21:15
Laravel
AveConstantis, 2021-06-02 19:21:15

How to connect PHPMailer in WP?

They say there is it under the hood, but how to get through to it? Or just transfer the folder with either to the root of the topic

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Brumer, 2021-06-02
@V_A_B

you can use the wp_mail function (well, or look into it at the same link it

described
...
    global $phpmailer;
 
    // (Re)create it, if it's gone missing. - (Повторно) создайте его, если он пропал 
   
    if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
        require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
        require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
        require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
        $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
 
        $phpmailer::$validator = static function ( $email ) {
            return (bool) is_email( $email );
        };
    }
...
and uses PHPMailer)
otherwise I won’t tell you much. never used PHPMailer directly because if the form is not the simplest, instead of wp_mail I use pure php - mail() function via sendmail. But that's how the letter went without
mistakes

global $phpmailer; //не помогло
//слизал подключение из wp_mail и отправилось
    // (Re)create it, if it's gone missing.
    if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
        require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
        require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
        require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
        $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
 
        $phpmailer::$validator = static function ( $email ) {
            return (bool) is_email( $email );
        };
    }

// Создаем письмо
$mail = $phpmailer;
$mail->isSMTP();                   // Отправка через SMTP
$mail->Host   = 'smtp.yandex.ru';  // Адрес SMTP сервера
$mail->SMTPAuth   = true;          // Enable SMTP authentication
$mail->Username   = 'login';       // ваше имя пользователя
$mail->Password   = 'password';    // ваш пароль
$mail->SMTPSecure = 'ssl';         // шифрование ssl
$mail->Port   = 465;               // порт подключения
 
$mail->setFrom('[email protected]', 'Иван Иванов');    // от кого
$mail->addAddress('[email protected]', 'Вася Петров'); // кому
 
$mail->Subject = 'Тест';
$mail->msgHTML("<html><body>
                <h1>Здравствуйте!</h1>
                <p>Это тестовое письмо.</p>
                </html></body>");
// Отправляем
if ($mail->send()) {
  echo 'Письмо отправлено!';
} else {
  echo 'Ошибка: ' . $mail->ErrorInfo;
}

60b7bde4a36c1614814137.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question