SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Invalid address: SMTP Error: Could not connect to SMTP host.

    Hi all,

    I am trying to configure PHPMailer for using it with Google Apps.
    When I call the function I get this error:
    SMTP -> ERROR: Failed to connect to server: Connection timed out (110)

    And after about 10 seconds, this one also:
    SMTP Error: Could not connect to SMTP host.

    I researched about this error and I have checked the e-mail address/password. It works fine as I am able to log into Google mail using them
    I also checked the port 465, using "telnet smtp.gmail.com 465" I got no error message, but also not an answer from the server, just a black screen.

    This is the finction I am using, if anyone can point me where the error is, I'd apreciate it a lot.
    Username and Password are just examples)

    <?php
    require("/home/libroman/public_html/phpmailer/PHPMailer_5.2.0/class.phpmailer.php");

    function smtpmailer($to, $from, $from_name, $subject, $body) {
    global $error;
    $mail = new PHPMailer(); // create a new object
    $mail->SMTPSecure = "ssl";
    $mail->Host='smtp.gmail.com';
    $mail->Port='465';
    $mail->Username = 'myemail@mydomain.com'; // SMTP account username
    $mail->Password = 'password';
    $mail->SMTPKeepAlive = true;
    $mail->Mailer = "smtp";
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->CharSet = 'utf-8';
    $mail->SMTPDebug = 0;
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);

    if(!$mail->Send()) {
    $error = 'Mail error: '.$mail->ErrorInfo;
    return false;
    } else {
    $error = 'Message sent!';
    return true;
    }
    }

    ?>

    Thanks a lot!!!!

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Sir_Arcturua View Post
    ...
    I researched about this error and I have checked the e-mail address/password. It works fine as I am able to log into Google mail using them
    I also checked the port 465, using "telnet smtp.gmail.com 465" I got no error message, but also not an answer from the server, just a black screen.
    Hi,

    If you have verified the port and the are using the proper smtp then if you can't connect using telnet it will never work using php mailer. It is likely that you have made an assumption about the smtp or port. You can also check DNS using nslookup to find if smtp.gmail.com is a valid route.

    Please don't waste your time trying to figure out if the PHP is incorrect until you are sure that you can connect to the smtp using simple means (via telnet).

    Steve
    ictus==""

  3. #3
    SitePoint Addict
    Join Date
    May 2011
    Posts
    242
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks a lot for your answer.

    I have checked what you suggested:
    - I am using port 25 instead of 465, checked with telnet and getting answer
    - Using nslookup and ping I receive answer from smtp.google.com

    The problem is when try to use PHPMailer, I get the same error message.

    Any othe idea?

  4. #4
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    Do you know if you need SMTP authentication on or off? Have you turned on SMTP debugging ie.
    Code:
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug  = 1; // errors and messages
    $mail->SMTPAuth   = true;
    Does the firewall on the server where php mailer is running have port 25 outgoing open or is NAT over-ridding this?

    Steve
    ictus==""


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •