Để thiết lập SMTP là thêm đoạn mã này vào file functions.php của bạn, điều này sẽ đảm bảo rằng WordPress sử dụng SMTP thay thế của phpmailer tiêu chuẩn.
Đoạn code như sau:
/* You can add your custom functions just below */
function myphpmailer( PHPMailer $phpmailer ){
$phpmailer->IsSMTP();
$phpmailer->Host = 'smtp.gmail.com'; // smtp host
$phpmailer->Port = '465'; // smtp port hoặc 587 tls
$phpmailer->Username = 'nguyenlap@gmail.com'; // smtp user
$phpmailer->Password = '********'; // SMTP pass - nên để mật khẩu ứng dụng
$phpmailer->SMTPAuth = true; // if required
$phpmailer->SMTPSecure = 'ssl'; // mã hóa smtp, giá trị này tùy vào smpt port
$phpmailer->CharSet ='utf-8';
$phpmailer->SetFrom('nguyenlap@gmail.com', get_option('blogname')); // Email gửi + Thông tin người gửi
}
add_action('phpmailer_init', 'myphpmailer');
