Posts tagged ‘smtp’

Using Gmail SMTP server with wordpress

I finally got the time to figure this one out. It’s not that hard. Wordpress by default uses phpmailer for sending and getting emails via POP3. PHPMailer can either use php mail() function (default) or SMTP and is essentially an abstraction around POP3 and SMTP protocols.

The version that shipped with my version of wordpress 2.0.x was using an older version of phpmailer and does not support TLS/SSL. SSL is supported, however, by phpmailer 2.3, the current version - so this is what you do:

  1. Download the latest version of PHP mailer
  2. Pay special attention to 3 files - class.phpmailer.php, class.pop3.php and class.smtp.php
  3. The 3 files listed in (2) above are stored in the {wordpress intall dir}/wp-includes dir as class-phpmailer.php, class-pop3.php and class-smtp.php respectively (please note that the period (.) is replaced with a dash (-))
  4. Copy the downloaded class. files to the wp-includes folder as the class- files (sudo cp {phpmailer dir}/class.phpmailer.php {wordpress install dir}/wp-includes/class-phpmailer.php
  5. Repeat step 4 for the pop3 and the smtp class as well
  6. Next open the file {wordpress install dir}/wp-includes/class-phpmailer.php and make the following changes - a. update the $port to have a defaulat value of 465 not 25, update the $host to have a default value of “smtp.gmail.com”, update the $SMTPSecure to “ssl”, update $SMTPAuth to “true” and then the $Username and $Password fields
  7. Now edit the {wordpress install dir}/wp-includes/pluggable.php, navigate to the function ‘wp_mail’ change the line $phpmailer->IsMail() to $phpmailer->IsSMTP()

That’s it.

Now when someone registers on your website or when someone adds a comment - you should get your emails via gmail. Happy blogging.