[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-11-08
7
Medium Priority
?
2,160 Views
Last Modified: 2012-05-10
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>
0
Comment
Question by:PegOC96
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34090252
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.
0
 

Author Comment

by:PegOC96
ID: 34092679
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  "
0
 
LVL 10

Assisted Solution

by:TRW-Consulting
TRW-Consulting earned 2000 total points
ID: 34093002
It sounds like your SMTP port is being blocked by a firewall, either outbound by your host, or inbound by the server you're trying to connect with. Do you have 'root' or 'Administrator' access to your server?
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 

Author Comment

by:PegOC96
ID: 34093267
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 ?
0
 
LVL 10

Accepted Solution

by:
TRW-Consulting earned 2000 total points
ID: 34098465
Yeah, you need to ask your hosting provider about this. Ask them if they have an SMTP server available for their clients and what the address/port is.  And if it requires authentication you will need a username/password.  If they don't provide one then ask them if they are blocking outbound traffic for SMTP requests, and if so see if they can remove that block for you, in which case you will need permission to access some outside SMTP service. Looking at your code above leads me to believe you have SMTP service at Godaddy.com, and if that's so then you should be able to get the port and username/password from them.
0
 

Author Comment

by:PegOC96
ID: 34115587
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.
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34115820
Good deal.  Glad you got it to work.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question