1

I am using this code to send emails using smtp:

require 'phpmailer/class.phpmailer.php';
 $mail = new PHPMailer(); // create a new object
  $mail->IsSMTP(); // enable SMTP
  $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
  $mail->SMTPAuth = true; // authentication enabled

  $mail->Host = "sr4.supercp.com";
  $mail->Port = 465; // or 587
  $mail->IsHTML(true);
  $mail->Username = "********";
  $mail->Password = "********";
  $mail->SetFrom("********");
  $mail->Subject = "Test";
  $mail->Body = "hello";
  $mail->AddAddress("****@gmail.com");
   if(!$mail->Send())
      {
      echo "Mailer Error: " . $mail->ErrorInfo;
        echo "<pre>";
        echo print_r($mail);
      }
      else
      {
      echo "Message has been sent";
      }

Getting this error:

2014-08-25 18:53:11 CLIENT -> SERVER: EHLO grabblaw.com
2014-08-25 18:53:11 SMTP ERROR: EHLO command failed:
2014-08-25 18:53:11 SMTP NOTICE: EOF caught while checking if connected SMTP connect() failed. Mailer Error: SMTP connect() failed.

I have spend entire day, but unable to make this work. Please help. Please refer this url for more error detailed info: http://grabblaw.com/mail_template.php

  • You're using an old version of PHPMailer. You'll also get more feedback on connection state if you set `$mail->SMTPDebug = 4;` – Synchro Aug 25 '14 at 19:48

2 Answers2

1

Similar to this question SMTP error with PHPMailer EHLO not supported

Changing your port to 25 should work: I tried to telnet:

telnet grabblaw.com 25 //works

telnet grabblaw.com 465 //hangs

telnet grabblaw.com 587 //no response
Community
  • 1
  • 1
Joe T
  • 2,300
  • 1
  • 19
  • 31
  • I am blank as these settings are working, without any change properly on a different site, but not in its sub domain, but after I edited the port to 25 and $mail->SMTPSecure = 'tls'; it is working fine. In the smtp settings it is stated for 465 port, but here I m getting it worked by 25. Anyways Thank You so much. :) – user3486228 Aug 26 '14 at 05:09
  • you might want to inquire with the server admin of grabblaw.com, why it's not responding on port 465. As Synchro said, you're better off with encryption and port 25 is usually not, but maybe it's not a big deal if you're not planning on passing sensitive data. – Joe T Aug 26 '14 at 06:23
1

You're setting:

$mail->Port = 465; // or 587

but there's no accompanying:

$mail->SMTPSecure = 'ssl'; // or 'tls'

So you're trying to send unencrypted data to an encrypted connection, which will not work (it's one of the reasons that SMTP over SSL was deprecated 15 years ago). TLS on 587 is more resistant to this.

Switching to port 25 usually means you're giving up on encryption altogether, which isn't a good solution.

Synchro
  • 35,538
  • 15
  • 81
  • 104