Avatar of PegOC96
PegOC96
 asked on

PHPMailer Problem: SMTP Error: Could not connect to SMTP host.

I am trying to use PHPMAILER on our site which is hosted on godaddy.com and am getting the
"SMTP Error: Could not connect to SMTP host" error message.  I have been able to set up an account in my mail client using the same host, username & password, so I believe those settings are correct.  Any suggestions on how I should procede?

To test, I am using an example form I found:  
if(isset($_POST["Submit"]))
{
require("class.phpmailer.php");
 
$mail = new PHPMailer();
 
////////////////////////////////////////////////////////////////
// Customize the following 5 lines with your own information. //
////////////////////////////////////////////////////////////////
 
$toaddress = "myemail@comcast.net";  //Change this to the email address you will be receiving your notices.
$mailhost = "smtpout.secureserver.net";  //Change this to your actual Domain name.

$fromaddress = "myemail@ourdomain.org";  //Change this to the email address you will use to send and authenticate with.

$frompwd = "mypassword";  //Change this to the above email addresses password.

 
//////////////////////////////////////////
// DO NOT CHANGE ANYTHING PAST THIS LINE//
//////////////////////////////////////////
 
$fromname = $_POST["TName"];
$body = $_POST["TBody"] ;
$rplyto = $_POST["TEmail"];
$msgbody = $fromname . "<br>" . $rplyto . "<br>" . $body;
 
$mail->IsSMTP();
$mail->Host = $mailhost;
$mail->SMTPAuth = true;
$mail->Username = $fromaddress;
$mail->Password = $frompwd;
 
$mail->From = $fromaddress;
$mail->FromName = $fromname;
$mail->AddReplyTo($rplyto);
$mail->AddAddress($toaddress);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msgbody;
 
if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
 
echo "Thank you, your message has been sent!";
}
 
?>
 
<html><body>
<form name="SendEmail01" method="post">
<table border=0>
<tr>
        <td>Name:</td>
        <td><input type="text" name="TName" size="30"></td>
</tr>
<tr>
        <td>Email:</td>
        <td><input type="text" name="TEmail" size="30"></td>
</tr>
<tr>
        <td>Body:</td>
        <td><textarea rows="4" name="TBody" cols="30"></textarea></td>
</tr>
<tr>
        <td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body></html>
PHPWeb Development

Avatar of undefined
Last Comment
TRW-Consulting

8/22/2022 - Mon
TRW-Consulting

You need to set the port number:

  $mail->Port = 25;

It's usually port 25, but they might set it to something else to try to discourage abuse.  And they should tell you somewhere. It might be 587 or 465 if it's using SSL or TLS.
PegOC96

ASKER
I had tried all of those  (I had seen that the port could be 25,80,3535, 587 or 465).   Using all of those, except 80, I still got the same "Mailer Error: SMTP Error: Could not connect to SMTP host." error message.  

When I use 80, I get:
Warning: fputs(): supplied argument is not a valid stream resource in D:\Hosting\4410081\html\dev\admin\mail\class.smtp.php on line 212
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.For 80,  I get  "
SOLUTION
TRW-Consulting

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PegOC96

ASKER
I don't think so.  We are on a Windows/shared hosting platform. Only have access to our www directories.

Do I need (can I)to ask tech support to unblock ?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
TRW-Consulting

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
PegOC96

ASKER
Thank you for your help.  I did contact tech support and they do have a block. But they gave me the name of the relay server to use (which does not use authentication)  and I have finally gotten a test file to work.
TRW-Consulting

Good deal.  Glad you got it to work.