PHPMailer is an open-source code that is used for sending emails from PHP applications. It is used by CMS like WordPress, Drupal, and Joomla. PHPMailer is the best PHP mail library alternative of PHP mail() function.
Examples of SMTP (Simple Mail Transfer Protocol) service providers that can be integrated with PHPMailer include Amazon SES, Gmail, Microsoft Outlook, SendGrid, Sendinblue, and Mailgun.
How PHPMailer Works with WordPress
If you are using WordPress, you do not have to go through intricate steps of installing PHPMailer library as WordPress comes with PHPMailer class. It is available at yourwebsite.com/public_html/wp-includes/class-phpmailer.php. This means you can start sending emails from your WordPress dashboard without any setting. You will be using your domain hosting SMTP server to send emails, for instance, box6176.bluehost[dot]com.
However, if you send bulk emails from a shared server; your web host may suspend your domain for exceeding web mail limits. Therefore, you need to use PHPMailer with a third-party SMTP service provider and it is simple to integrate in WordPress.
You just need to add the code linked below to your theme’s functions.php file. Make sure that you have customized the fields marked in red (use this method with precaution).
Download Code from WordPress Codex.
WARNING: I do not recommend adding the code provided above to functions.php as it poses a lot of security issues. You’d better use this wp_config.php route.
Update: WordPress 5.5 now supports PHPMailer version 6.1.6.
Features of PHPMailer
PHPMailer can be installed on systems like Linux, Windows, and Ubuntu server. Some of the capabilities and features of PHPMailer library include:
- Can be used to send emails to multiple recipients with Bcc and Cc
- Can be used to reply to emails
- You can attach files in your emails
- Supports UTF-8
- Email Validation
- DKIM (Domain Keys Identified Mail) and SPF (Sender Policy Framework) setup
- You can send emails without a local server
- SMTP authentication
- SMTP SSL encryption
- You can use it to send HTML emails (Read on best HTML Email Templates)
- Can be used for creating contact forms
How to setup PHPMailer on cPanel
Below is a basic PHPMailer setup guide for cPanel users:
- Go to GitHub and download PHPMailer (stable) Zip file
- Create an Email Address on cPanel or use your Gmail
- Go back and click File Manager
- Create a new folder in Public HTML
- Open the folder you have created and upload the Php Mailer Zip file that you downloaded from GitHub
- Extract the Zip file
- Create a new file and name it mail.php
- Open the mail.php file and enter this code (Edit and customize the code you have just copied to include your SMTP email credentials)
- Click save changes button
Requirements for Installing PHPMailer for Windows
To install PHPMailer on windows you need a website Development environment like XAMPP, EasyPHP, or WAMP and Composer. If you want to use PHPMailer without Composer, you can download PHPMailer zip file from GitHub and extract it into your preferred directory.
Important: If you manage to properly Install PHPMailer library in your server and setup SMTP authentication, then it means that you do not need to install SMTP WordPress plugins for email deliverability.