Using SSL/TLS when sending an email from PHP


Sometimes we will need to send email from a PHP script on server encrypted using SSL or TLS before it is sent to the recipient's mail server.

Below are the modifications you need to implement in the php code for sending mail using class.phpmailer.php


1) You need to enable SSL/TLS for your Apache/PHP installation. Edit your php.ini file and enable extension=php_openssl.dll


2) Make sure you have libeay32.dll and ssleay32.dll in your /apache/bin folder.


3) Then restart Apache and your SSL should be loaded.


4) Download latet version of php mailer (Have tested with PHPMailer_v5.1)

5) Update class files in your mail configuration folder (class.phpmailer.php, class.smtp.php,.....)

6) Do the below modifications in the class.phpmailer.php

//******************* COnfiguring for smtp.office365.com  *************************

Note: Microsoft exchange server implements NTLM authentication.

  a)  public $Port  = 587;

  b)  public $SMTPSecure    = 'tls';
 
    c) public $SMTPAuth      = true;

    d) Host = "smtp.office365.com";
   
 //******************* COnfiguring for smtp.gmail.com  *************************  
   
 Note: Gmail SMTP implements SSL authntication
   
     public $Port          = 465;
     public $SMTPSecure    = 'ssl';
     Host = "smtp.gmail.com";

No comments:

Post a Comment