If you are doing WordPress plugin development that need to send out email, i think it’s a good idea to set the SMTP settings in your own plugin instead of using other third party SMTP plugin. It’s not that third party plugin is not good, but some times due to the plugin priority issue, the email might not sent out. This might because of the priority issue.
To send email using SMTP in your own WordPress plugin, follow the code below:-
Advertisements
- Open your theme functions.php file and follow the steps below
- Then you need to add this action ‘phpmailer_init’:-
add_action('phpmailer_init', 'techie_phpmailer_init_smtp');
- then create the function below to specify your smtp settings:-
function techie_phpmailer_init_smtp($phpmailer) { $phpmailer->Mailer = 'smtp'; $phpmailer->Sender = 'noreply@mysmtp.com'; $phpmailer->SMTPSecure = 'ssl'; $phpmailer->Host = 'mail.mysmtp.com'; $phpmailer->Port = 465; $phpmailer->SMTPAuth = TRUE; $phpmailer->Username = 'username@mysmtp.com'; $phpmailer->Password = 'mypassword'; $phpmailer = apply_filters('wp_mail_smtp_custom_options', $phpmailer); }
** Please change all the smtp settings to your smtp settings.
- Now all the email sent out from your plugin will go thru SMTP.
Of course, you can create your own interface to allow user to change their SMTP preference.
This is just a simple example to show you how to solve the SMTP email problem in WordPress.
Happy Coding!
Related posts:
Woocommerce: How to bcc all order email to multiple recipients according to status
How to remove #more tag in WordPress
OpenOffice Calc worksheet tab went missing
How to insert new line (line break) in a cell - OpenOffice Calc
Composer: PHP Fatal error: Allowed memory size of ... exhausted...
How to disable ssh root login?
CPAN Error: make test had returned bad status, won't install without force
How to add calendar in Thunderbird - Lightning Calendar add-on
Share this with your friends:-