Loading PHPMailer inside plugins and creating custom functions

This is a straightforward task, where we have to include the files and initialize the PHPMailer class, as shown in the following code:

    require_once ABSPATH . WPINC . '/class-phpmailer.php';     require_once ABSPATH . WPINC . '/class-smtp.php';     $mailer = new PHPMailer( true );  

Then, we can use the $mailer variable object to configure and send e-mails as described in the official documentation.

By default, WordPress uses the default mail server of your web host to send e-mails. This doesn't involve sender e-mail authentication, and hence, is the reason behind spam e-mails.

We can prevent e-mail spamming by authenticating the e-mail through Simple Mail Transfer Protocol (SMTP). Here, ...

Get Wordpress Web Application Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.