Cannot send e-mails by SSL/TLS

Discussion in 'Troubleshooting' started by freyesm, Mar 20, 2011.

  1. freyesm

    freyesm New Member

    Joined:
    Mar 11, 2011
    Messages:
    8
    Hi,

    I'm using the last version (3.2.3PRO), and I really need SSL/TLS support for sending e-mails.

    I have a payed gmail account (premium), so it requires SSL/TLS authentication. I just cannot use the "internal" method because my hosting have a stupid policy to forbidden to send more than 10 e-mails per HOUR !

    Under Admin > E-Mail > E-Mail System Configuration

    - Internal PHP mail() function (default) does works fine, but just cannot use that one (see reason above).

    - SMTP is the problem here.

    Using old included class.phpmailer.php & class.smtp.php I was getting:
    Code:
    No SSL or TLS:
    WARNING: fsockopen(): unable to connect to smtp.googlemail.com:465 (Connection timed out) in line 122 of file class.smtp.php
    
    Email method verification
     
    # There was an error sending the email message
    # SMTP Error: Could not connect to SMTP host.
    
    Using SSL:
    WARNING: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out) in line 122 of file class.smtp.php
    
    Using TLS:
    WARNING: fsockopen(): unable to connect to tls://smtp.googlemail.com:465 (Connection timed out) in line 122 of file class.smtp.php
    Then I decided to update PHPMailer from 2.0.4 (included) to 5.1, but now I'm getting this error:
    SMTP Error: Could not connect to SMTP host.

    Email method verification

    # There was an error sending the email message
    # SMTP Error: Could not connect to SMTP host.

    What now?

    Thanks,
    Fernando
  2. freyesm

    freyesm New Member

    Joined:
    Mar 11, 2011
    Messages:
    8
    I have found this and looks like PHPMailer isn't the problem:
    http://mediakey.dk/~cc/send-email-using-php-phpmailer-and-gmail/

    Code:
    # $mail->Mailer = "smtp";  
    # $mail->Host = "ssl://smtp.gmail.com";  
    # $mail->Port = 465;  
    # $mail->SMTPAuth = true; // turn on SMTP authentication  
    # $mail->Username = "username@gmail.com"; // SMTP username  
    # $mail->Password = "password"; // SMTP password
    Instructions from Gmail:
    [​IMG]

    From PHPMailer:
    Code:
    <?php
    
    // example on using PHPMailer with GMAIL
    
    include("class.phpmailer.php");
    include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
    
    $mail             = new PHPMailer();
    
    $body             = $mail->getFile('contents.html');
    $body             = eregi_replace("[\]",'',$body);
    
    $mail->IsSMTP();
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 465;                   // set the SMTP port
    
    $mail->Username   = "yourname@gmail.com";  // GMAIL username
    $mail->Password   = "password";            // GMAIL password
    
    $mail->From       = "replyto@yourdomain.com";
    $mail->FromName   = "Webmaster";
    $mail->Subject    = "This is the subject";
    $mail->AltBody    = "This is the body when user views in plain text format"; //Text Body
    $mail->WordWrap   = 50; // set word wrap
    
    $mail->MsgHTML($body);
    
    $mail->AddReplyTo("replyto@yourdomain.com","Webmaster");
    
    $mail->AddAttachment("/path/to/file.zip");             // attachment
    $mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
    
    $mail->AddAddress("username@domain.com","First Last");
    
    $mail->IsHTML(true); // send as HTML
    
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message has been sent";
    }
    
    ?>
  3. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    This is working for me.

    What are you entering for your various SMTP settings for aMember (ie. hostname, username)..
  4. freyesm

    freyesm New Member

    Joined:
    Mar 11, 2011
    Messages:
    8
    User: my e-mail
    Pass: my pass
    Host: smtp.googlemail.com (tried smtp.gmail.com too, no joy)
    Port: 465
    Security: SSL (tried TLS too)

    Using test gmail e-mail, to another of my gmail account.

    Always getting: SMTP Error: Could not connect to SMTP host.

    Looks like 465 port is begin blocked on webhosting, might be that.
  5. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    user: your email
    pass: your pass
    host: smtp.gmail.com
    port: Can try either 465 or 587 depending on your host config
    security: ssl

    I have seen many webhosts blocking 465 and 587 so that is a good place to start. (can try a manual telnet from ssh to check)
  6. freyesm

    freyesm New Member

    Joined:
    Mar 11, 2011
    Messages:
    8
    Confirmed, they are blocking such ports.

    Sigh.

Share This Page