Jump to content

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not


NaniG

Recommended Posts

Firstly I'd like to say a hello to everyone.

 

OK, I'm having a problem with my PHPMailer setup. My aim is to have a registration email sent to a user upon sign up from ([email protected]). I have set up my mail servers set up correctly. so I can send/recieve mail from ([email protected]).

 

I am using PHPMailer_v5.1, and am using the following code

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once('../class.phpmailer.php');

$mail = new PHPMailer();

$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP();
$mail->Host = "[email protected]";
$mail->SMTPDebug = 1;

$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "[email protected]";
$mail->Port = 25;
$mail->Username = "[email protected]";
$mail->Password = "*****"; 

$mail->SetFrom('[email protected]","My Domain');
$mail->AddReplyTo("[email protected]","My Domain");
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);

$address = "[email protected]";
$mail->AddAddress($address, "Test");

if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
  echo "Message sent!";
}
?>

 

I set up a PHP document to test this mail feature, but every time I load it, it displays this

 

SMTP -> ERROR: Failed to connect to server: (0)

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

 

The PHPMailer is running on Elastiks (CentOS Linux 5.6).

 

I cross checked the php.ini file and  the OpenSSL is enabled.

 

openssl

OpenSSL support  enabled 

OpenSSL Version  OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 

 

Please help me out from these issue.

 

Thanks for your time guys, hope someone can get back to me soon!

hello :)

 

i would test a simple send with mail() before debugging that:

 

http://php.net/manual/en/function.mail.php

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

<?php
mail('[email protected]', 'My Subject', $message);
?>

 

that will confirm that php smtp is working, and then you can debug phpmailer

$mail->Host = "[email protected]";
...
$mail->Host = "[email protected]";

 

1) You don't need to set the host twice.

 

2) The host should just be a domain name like smtp1.mydomain.com, not an email address.

 

Thanking you guys for quick reply!

 

Already i used the mail() function in my pages. but the problem is that the mail is going into spam. To avoid this, i wanted to use the PHPMailer with SMTP authentication. We have created our own domain and we wants to go all the mails through our domain.

 

$mail->host='mail.domainname.com';

 

Again am getting the same error :

 

SMTP -> ERROR: Failed to connect to server: (0)

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

 

Please help me out from these issue.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.