LiquidLayer.net | Tech

Easy SMTP email settings for WordPress628

LiquidLayer private msg quote post Address this user
Source ButlerBlog.com

About Chad Butler
Chad Butler is both a freelance writer and web developer. He has developed several popular WordPress plugins and his writing has appeared on forbes.com, sfomag.com, and investopedia.com.

*** A great write up by Chad Butler via his blog regarding Word Press and sending email:

I’ve written a number of posts on the WordPress email settings for using the mail function wp_mail. Some of this has been information on troubleshooting your WordPress email settings, and one of the solutions to problems with wp_mail that I have addressed in the past has been to use an SMTP server for sending mail rather than relying on the webserver.

For some, this may be something you want to use a plugin for, since WordPress does not have much in the way of email settings in the admin panel. There are several plugins available for this. But personally, I prefer to not use plugins when a very simple code snippet will do.

Setting up WordPress to use SMTP for sending email is extremely simple. You don’t really need any different information than you would for email plugin settings. All you need is your login credentials, the account information, server location and you can do this all with a few lines of code added to your functions.php file.

Sound good? Great – let’s get started.

WordPress’s email function wp_mail is essentially a wrapper for phpmailer, a popular email class for PHP. WordPress has a little known action hook when phpmailer is initialized, phpmailer_init. This allows you to establish the phpmailer instance as using SMTP.

Here is a code snippet example with comments for each setting to configure WordPress to sent SMTP email:

=============================================================
add_action('phpmailer_init','send_smtp_email');
function send_smtp_email( $phpmailer )
{
// Define that we are sending with SMTP
$phpmailer->isSMTP();

// The hostname of the mail server
$phpmailer->Host = "smtp.example.com";

// Use SMTP authentication (true|false)
$phpmailer->SMTPAuth = true;

// SMTP port number - likely to be 25, 465 or 587
$phpmailer->Port = "587";

// Username to use for SMTP authentication
$phpmailer->Username = "yourusername";

// Password to use for SMTP authentication
$phpmailer->Password = "yourpassword";

// The encryption system to use - ssl (deprecated) or tls
$phpmailer->SMTPSecure = "tls";

$phpmailer->From = "your-email-address";
$phpmailer->FromName = "Your Name";

=============================================================

To use this snippet, you will need to adjust the settings according to your email service requirements. Check with your host.

The snippet, once configured, can be added to your theme’s functions.php file.

For more information on testing, troubleshooting, and changing your WordPress email configuration for wp_mail, here are some additional posts:

Testing your WordPress email settings for the wp_mail function – some information on wp_mail and a testing script you can use to make sure it is sending messages.

Troubleshooting wp_mail WordPress Email Configuration – not everything that can go wrong is directly a problem with WP. This post has information on host restrictions and other outside problems that should be checked.

WordPress Email Settings: Changing the wp_mail address with a simple plugin – here is a very simple and lightweight script you can load as a plugin to change the email address that WordPress sends email from.

Changing the wp_mail from address in WordPress without a plugin – provides a simple code snippet you can use to change the email address that WordPress sends from, no plugin required.

See the post above via Chad Butlers Blog :

Source ButlerBlog.com

Liquid Layer Networks | Performance Cloud Web Hosting
http://www.LiquidLayer.net

ParagonHost Networks | Since 2000
http://www.ParagonHost.net
Post 1 IP   flag post
SethAbbott private msg quote post Address this user
Hey mate, your explanation was quite impressive. Thanks for posting.

By this procedure one can easily send emails from his WP blog using preferred SMTP server. I was just wondering prior to exploiting SMTP email settings via hand codes, we should try out some associated WordPress plugins. It will relatively be easier. Instead, we can also do the same manually by following procedure given in this thread https://wordpress.org/plugins/easy-wp-smtp/.
Post 2 IP   flag post
1087 2 2
Log in or sign up to compose a reply.