smtp is not working in php - Godaddy hosting service

寵の児 提交于 2019-12-12 05:41:24

问题


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.


回答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;



回答2:


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;
}



回答3:


@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;


来源:https://stackoverflow.com/questions/32667927/smtp-is-not-working-in-php-godaddy-hosting-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!