Last active
April 22, 2023 16:47
-
-
Save cdsaenz/aa16e51cee16af1abd24653c7b281bc4 to your computer and use it in GitHub Desktop.
WP Mail using authenticated SMTP without a plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PHPMailer\PHPMailer\PHPMailer; | |
// Set up SMTP settings | |
add_action( 'phpmailer_init', 'wpse_phpmailer_init' ); | |
function wpse_phpmailer_init( PHPMailer $mailer ) { | |
$mailer->isSMTP(); | |
$mailer->Host = ''; // replace with your SMTP server hostname | |
$mailer->SMTPAuth = true; | |
$mailer->Username = ''; // replace with your SMTP username | |
$mailer->Password = ''; // replace with your SMTP password | |
$mailer->SMTPSecure = 'ssl'; // or tls | |
$mailer->Port = 465; // replace with your SMTP port number | |
} | |
$to = '[email protected]'; | |
$subject = 'Test Email with HTML Content'; | |
$message = '<html><body><h1>Hello, World!</h1><p>This is a test email with <strong>HTML content</strong>.</p></body></html>'; | |
$headers = array('Content-Type: text/html; charset=UTF-8'); | |
// Send the email | |
if (wp_mail($to, $subject, $message, $headers)) { | |
error_log('Email sent'); | |
} | |
else { | |
error_log('Email NOT sent'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment