Answer the question
In order to leave comments, you need to log in
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
you can use the wp_mail function (well, or look into it at the same link it
...
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 );
};
}
...
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;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question