Home    Articles

 

How to send emails with SMTP in WordPress

 

wordpress-logo-14064_500x210

In order to send emails in WordPress using SMTP you need to configure the wp_mail() function at your server.

To do that you need to use PHPMailer Class that contains the SMTP settings and will take care of sending the emails.

To use this class we have to call the action like that:

add_action( 'phpmailer_init', 'configure_smtp' );
function configure_smtp( PHPMailer $phpmailer ){
    $phpmailer->isSMTP(); //switch to smtp
    $phpmailer->Host = 'mail.domain.com';
    $phpmailer->SMTPAuth = true;
    $phpmailer->Port = 25;
    $phpmailer->Username = 'email@domain.com';
    $phpmailer->Password = 'password';
    $phpmailer->SMTPSecure = false;
    $phpmailer->From = 'sender@domain.com;
    $phpmailer->FromName='The Name of the Sender';
}

In the code above we call some functions like isSMTP() and we provide the proper credentials for the email account that will be used.

This is all we have to do to make WordPress to send emails using SMTP.

Enjoy.

…first time posted on w3bdeveloper.com

by