You’ve been hired as DEVELOPER to put up a company’s website. As the work evolves, you find out emails are not being sent. So you search for a SMTP an install it.

Seriously… wouldn’t be that difficult to configure it by yourself. As a remind, WordPress has a built-in hook just for that.

That’s nothing to do with any “devs pride”. You know, as developer, that most plugins bring a lot of crap on top of the feature we are actually looking for.

Instead of a dozen lines of code (because they are enough), we get another useless plugin, sometimes with notices and dialogues with ads.

Sounds great, but how could I do that?

WordPress uses PHPmailer to send transactional emails like many other scripts.

Including the credentials for SMTP is really easy, and if you like, you can just add an options page to make them editable. Actually, I have no idea why WP hasn’t had this done yet. Till there, you can easily set up your own SMTP manager by using the hook.

function smtp_setup( PHPMailer $phpmailer ) {
    $phpmailer->Host = '';
    $phpmailer->SMTPAuth = true; // Ask it to use authenticate using the Username and Password properties
    $phpmailer->Port = 25;
    $phpmailer->Username = 'yourusername';
    $phpmailer->Password = 'yourpassword';
    // Additional settings…
    //$phpmailer->SMTPSecure = 'tls'; // Choose 'ssl' for SMTPS on port 465, or 'tls' for SMTP+STARTTLS on port 25 or 587
    //$phpmailer->From = "";
    //$phpmailer->FromName = "Your Name";
add_action( 'phpmailer_init', 'smtp_setup' );