1

I am trying to use php-mailer-class but getting different issue.

Please take a look on my code.

include ("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 = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->Username = "admin@****.in"; 
$mail->Password = "******";          
$mail->SetFrom('*****0014@gmail.com', 'User name');
$mail->Subject = 'mailing';
$mail->Body = "<b>Hi, your e- mail has been received.</b>";
$mail->AddAddress("*****0014@gmail.com");
if(!$mail->Send()) {
   $error = 'Mail error: '.$mail->ErrorInfo;
   return false;
} else {
$error = 'Message sent!';
   return true;
}

errors-:

SMTP -> ERROR: EHLO not accepted from server: 
SMTP -> ERROR: HELO not accepted from server: 
SMTP -> NOTICE: EOF caught while checking if connectedThe following From address failed: *****0014@gmail.com

This code is working well if I am using Gamil settings Not working with godaddy SMTP settings.

Subin Thomas
  • 1,408
  • 10
  • 19
Vipul sharma
  • 1,245
  • 1
  • 13
  • 33
  • 1
    smtp has nothing to do with php its server side not from php side – NullPoiиteя Sep 19 '15 at 12:09
  • Probably the relay forbids unencrypted smtp connections on port 25? – tillz Sep 19 '15 at 12:25
  • You have not included class.smtp of phpmailer @vipul Sharma – Subin Thomas Sep 19 '15 at 12:40
  • I am using godaddy is well.! Godaddy doesn’t allow out SMTP servers, like gmail, or others. they force users to use their own servers, I used SMTP with godaddy it was to slow, and mails were coming after 3-5 minutes or was never getting emails sometimes, I switched to mail() function still slow but much better than using godaddy SMTP servers. I recommend you to use mail() function instead. Side note : godaddy is a horrible hosting provider service. –  Mar 25 '20 at 10:37
  • I have been facing the same problem. I have tried using the mail() function, emails are delivered, but sent emails are not saved. I am using gmail. – C. Kalita Apr 26 '22 at 06:36

4 Answers4

1

I checked your code, and expecting few reasons for the error.

  1. Port no/host declaration wrong
  2. SMTP class not available.

if the above both are solved, please modify the code by adding the extra line as follows.

$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->SMTPAuth   = true; 

This found working well in my server.

From THIS question, it describes the server blocking of SSL SMTP connection in shared hosting. So make the mailer to use TLS, to do so, change port no and SMTP mode.

$mail->SMTPSecure = "tls";
$mail->Port = 587;

And specifically you told that you are using godaddy hosting, as per This question, change your host configuration to

$mail->Host = localhost;
Community
  • 1
  • 1
Subin Thomas
  • 1,408
  • 10
  • 19
1

Too late but helpful for other.

GoDaddy blocks all outgoing SMTP connections except for their own.

Call GoDaddy and ask them to add SMTP relay (eg gmail smtp.gmail.com) on server.

Yogesh Saroya
  • 1,401
  • 5
  • 23
  • 52
0

First include include("PHPMailerAutoload.php"); and PHPmailerAutoload.php will load a class that you need, in your case class.smtp.php.

include("PHPMailerAutoload.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 = "ssl"; // sets the prefix to the servier
$mail->Host = "box###.bluehost.com"; // sets the SMTP server
$mail->Port = 465; // set the SMTP port

$mail->Username = "admin@****.in"; 
$mail->Password = "******";          
$mail->SetFrom('admin@****.in', 'Sender name');
$mail->Subject = 'mailing';
$mail->Body = "<b>Hi, your e- mail has been received.</b>";
$mail->AddAddress("*****0014@gmail.com", "User name");
if(!$mail->Send()) {
   $error = 'Mail error: '.$mail->ErrorInfo;
   return false;
} else {
$error = 'Message sent!';
   return true;
}
Mladen
  • 1
  • 4
  • Can you explain the changes?? @Mladen – Subin Thomas Sep 19 '15 at 13:21
  • @SubinThomas SetForm must be same value as username because you canot send email from admin@****.in using SMTP as another person/email. – Mladen Sep 19 '15 at 13:26
  • You can set anything in setfrom. even can be CEO@google.com – Subin Thomas Sep 19 '15 at 13:32
  • @vipulsharma does you hosting support smtp? Do u use shared hosting or VPS? – Mladen Sep 19 '15 at 13:39
  • @vipulsharma i just edit code for sharedhosting on bluehost. – Mladen Sep 19 '15 at 13:50
  • @vipulsharma HOST "box###.bluehost.com" u can find when u login to ur bluehost acc then go to Email Accounts on select ur email adress and click on more button and then on Cofigure Email Client. When new page load u can find ur SMTP, PORT and all other stuff u need. The same procedure is forl all shared hosting who use cpanel – Mladen Sep 19 '15 at 13:57
0

@vipulsharma,Its simple, you don't need to mentions host url directly to "relay-hosting.secureserver.net" because you are using the shared hosting so you have to point your host destination to your localhost folder only. For shared hosting, GoDaddy already configured the host setting internally. do change in the following changes in your code.

$mail->Host= 'localhost';
$mail->ssl=false;
$mail->authentication=false;
$mail->Port=25;
vignesh Subash
  • 2,577
  • 1
  • 11
  • 15