Sending WordPress emails using SMTP is pretty straight forward so rather than using a plugin we can insert a small snippet to do the same thing. All you need for sending WordPress emails via SMTP are your mail server credentials such as username, password and server address.
The WordPress email function wp_mail is essentially a wrapper for phpmailer which is a popular email class for PHP. WordPress has an action hook called phpmailer_init which allows us to establish the phpmailer instance using SMTP.
Here is a code snippet to configure WordPress to sent SMTP emails.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
add_action('phpmailer_init','es_send_smtp_email'); function es_send_smtp_email( $phpmailer ) { $phpmailer->isSMTP(); // Mail server $phpmailer->Host = "smtp.example.com"; // Use SMTP authentication $phpmailer->SMTPAuth = true; // SMTP port number $phpmailer->Port = "465"; // Username $phpmailer->Username = "yourusername"; // Password $phpmailer->Password = "yourpassword"; // The encryption system $phpmailer->SMTPSecure = "tls"; $phpmailer->From = "your-email-address"; $phpmailer->FromName = "Your Name"; } |