Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

SMTP over SSL

Help
Stan
2005-02-01
2012-09-18
  • Stan
    Stan
    2005-02-01

    Hi,

    I was just wondering if there is a way of establishing a connection with SMTP server over SSL? If that's the case could you please give a short example.
    Thanks for help

     
    • yushun
      yushun
      2006-07-24

      Guys, after hours of research, here is how you do it:

      1. add a new variable for both the SMTP and PHPMailer class:

      var $Protocol = '';

      1. Add this line to the Connect() function in the SMTP class

        if($this->Protocol) $host = $this->Protocol."://".$host;
        
      2. change to fgets() to @fgets() to surpass the ssl error

      3. add this line when the SMTP instance is created in class.phpmailer.php

        function SmtpConnect() {
        if($this->smtp == NULL) { $this->smtp = new SMTP();}

        //add this
        $this->smtp->Protocol = $this->Protocol;
        ......
        ......

      4. add this line in your email.php file

      $mail->Protocol = "ssl";

      DONE!!!! It was sweet.

       
    • berserker7o3
      berserker7o3
      2005-07-15

      i also would like to know this

       
    • Geeb
      Geeb
      2005-07-19

      Same here. We're all thinking "Gmail", right?
      :-)

       
    • There isn't a way to do that in PHPMailer right now. It wasn't possible in the past because PHP didn't have great SSL support. It might be possible now.

       
    • Chris Padfield
      Chris Padfield
      2005-11-20

      I have sort of got this to work in PHP 5.0.4.

      If you change the line (around 83) from:

      fsockopen($host, $port ....

      to

      fsockopen('ssl://' . $host, $port ....

      well it works. I can send email through gmail. The problem is I also get this error:

      Warning: fgets() [function.fgets]: SSL: fatal protocol error in I:\apachefriends\xampp\htdocs\deskpro\3.0.0\includes\3rdparty\phpmailer\class.smtp.php on line 1020

      Now I think this is related to this:

      http://bugs.php.net/bug.php?id=23220

       
      • Onyr
        Onyr
        2006-07-08

        In which file do you have to change that?

         
      • Johnny
        Johnny
        2006-04-04

        Thanks Chris
        It works and I now have exactly the same error message as yours.

        I am using PHP 4.3.11.

         
    • Abdullah Rafiq
      Abdullah Rafiq
      2006-03-18

      I tried and tried and tried. But phpmailer just can not send email through Gmail smtp servers.

      ssl://smtp.gmail.com
      tls://smtp.gmail.com

      Nothing works. Any help would be appreciated. Googling doesn't reveal much either.