0

Today i was doing some mailing stuff in the php, I found that there are two methods for that one is the simple mail function provided by the Php and the second i found on the internet it was about using the PHP mailer class from the site https://github.com/PHPMailer/PHPMailer. the problem is that which i run my program than the mail is not being sent. Let's have a look at the code

<?php
include 'PHPMailer-master/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->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail

$mail->Host = "smtp.gmail.com";
$mail->Port = 465; # or 587

$mail->IsHTML(true);
$mail->Username = "singh6@gmail.com";
$mail->Password = "88888*******";

$mail->SetFrom('singh@gmail.com');
$mail->AddAddress('sanu@gmail.com');
$mail->Subject = "Test";
$mail->Body    = "hello";

$sendResult = $mail->Send();

if ($sendResult)
{
     echo "Message has been sent";

}
else
{
     echo "Mailer Error: " . $mail->ErrorInfo;
}

Now when I run this script I get the following error:

CLIENT -> SMTP: EHLO localhost 
SMTP -> ERROR: EHLO not accepted from server: 
CLIENT -> SMTP: HELO localhost

Notice: fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\program\mailsending1\mailsending_v1\PHPMailer-master\class.smtp.php on line 1023

SMTP -> ERROR: HELO not accepted from server: 
SMTP -> NOTICE: EOF caught while checking if connected
SMTP Connect() failed. 
Mailer Error: SMTP Connect() failed.
hakre
  • 193,403
  • 52
  • 435
  • 836
Anurag Singh
  • 727
  • 6
  • 10
  • 27
  • 1
    tried ' $mail->ErrorInfo ' to get the error? – Vipin Kumar KM Aug 12 '13 at 05:52
  • 2
    Replace `"sending failed"` with `$mail->ErrorInfo` and post the error message. – Nabil Kadimi Aug 12 '13 at 05:52
  • 1
    posibble duplicate http://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer – machineaddict Aug 12 '13 at 05:54
  • Can you post the error message suggested above? –  Aug 12 '13 at 05:54
  • Fatal error: Call to undefined method PHPMailer::ErrorInfo() in C:\xampp\htdocs\program\mailsending\mail_notification\mailsend_v2.php on line 28. this the error which i get – Anurag Singh Aug 12 '13 at 05:54
  • just ErrorInfo, not ErrorInfo() – Vipin Kumar KM Aug 12 '13 at 05:55
  • Notice: fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\program\mailsending\mail_notification\PHPMailer-master\class.smtp.php on line 1023 sending failedSMTP Connect() failed. – Anurag Singh Aug 12 '13 at 06:01
  • The error says it all, the remote host closes the connection. Contact the provider of the remote host and ask about the specification of how their system is intended to work with your system. As far as PHPMailer and GMail is concerned, this is likely duplicate material here on stackoverflow. – hakre Aug 12 '13 at 07:15
  • You're running on windows. Are you sure that `$mail->SMTPSecure = 'tls';` is supported by your system? How did you verfiy? – hakre Aug 12 '13 at 07:23
  • Try `$mail->SMTPSecure = 'SSL'; $mail->Host = 'ssl://smtp.gmail.com';` and see if it works. Also verify ports: https://support.google.com/mail/answer/13287?hl=en - TLS requires 587, SSL requires 465 - You're using the wrong port for TLS. – hakre Aug 12 '13 at 07:30
  • Also mind two-step verification: https://support.google.com/accounts/answer/185833?hl=en – hakre Aug 12 '13 at 07:35
  • possible duplicate of [PHP mailer error](http://stackoverflow.com/questions/2227702/php-mailer-error) – hakre Aug 12 '13 at 07:36
  • $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->SMTPSecure = 'SSL'; // secure transfer enabled REQUIRED for GMail $mail->Host = 'ssl://smtp.gmail.com'; $mail->Port = 465; // or 587 this was my formatted code – Anurag Singh Aug 12 '13 at 07:41
  • now the error is: SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1546610735)SMTP Connect() failed. Mailer Error: SMTP Connect() failed. – Anurag Singh Aug 12 '13 at 07:42
  • 1
    try uncommenting the line **extension=php_openssl.dll** in your php.ini – Vipin Kumar KM Aug 12 '13 at 10:32
  • You might be using it in local machine – saravanabawa Nov 23 '16 at 03:14

2 Answers2

0

Change the SMTP port to 465. It should work

Kasun Rajapaksha
  • 536
  • 1
  • 5
  • 22
0

first try this to find errors

if ($mail->Send()) 
{
echo "mail send sucessfully";
}
else 
{
echo "sending failed";
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

put body in your mail

$mail->Body="<!DOCTYPE html>
<html lang='en-us'>
<head>
<meta charset='utf-8'>
<title></title>
</head>
<body>
<div>
</div>
</body>
</html>";
chirag ode
  • 950
  • 7
  • 15
  • Notice: fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\program\mailsending\mail_notification\PHPMailer-master\class.smtp.php on line 1023 sending failedSMTP Connect() failed. – Anurag Singh Aug 12 '13 at 06:02
  • try this $mail->Host = 'smtpout.secureserver.net'; $mail->Port = '80'; – chirag ode Aug 12 '13 at 06:05
  • i added the body and used the host and the port u provided but i get the error:SMTP Connect() failed. – Anurag Singh Aug 12 '13 at 06:09
  • do this $mail->SMTPSecure = ''; – chirag ode Aug 12 '13 at 06:10
  • check your username and password – chirag ode Aug 12 '13 at 06:15
  • @user1334573 : use $mail->SMTPDebug = 1; to debug – Vipin Kumar KM Aug 12 '13 at 06:18
  • Notice: fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\program\mailsending\mail_notification\PHPMailer-master\class.smtp.php on line 1023. this the error now sending failedSMTP Connect() failed – Anurag Singh Aug 12 '13 at 06:20