NaniG Posted February 2, 2012 Share Posted February 2, 2012 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 (admin@mydomain.com). I have set up my mail servers set up correctly. so I can send/recieve mail from (admin@mydomain.com). 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 = "admin@mydomain.com"; $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; $mail->Host = "admin@mydomain.com"; $mail->Port = 25; $mail->Username = "admin@mydomain.com"; $mail->Password = "*****"; $mail->SetFrom('admin@mydomain.com","My Domain'); $mail->AddReplyTo("admin@mydomain.com","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 = "test@test.com"; $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! Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/ Share on other sites More sharing options...
digibucc Posted February 3, 2012 Share Posted February 3, 2012 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('caffeinated@example.com', 'My Subject', $message); ?> that will confirm that php smtp is working, and then you can debug phpmailer Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1313853 Share on other sites More sharing options...
kicken Posted February 3, 2012 Share Posted February 3, 2012 $mail->Host = "admin@mydomain.com"; ... $mail->Host = "admin@mydomain.com"; 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. Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1313856 Share on other sites More sharing options...
NaniG Posted February 3, 2012 Author Share Posted February 3, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1314073 Share on other sites More sharing options...
digibucc Posted February 3, 2012 Share Posted February 3, 2012 have you confirmed those settings in a program like thunderbird? Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1314081 Share on other sites More sharing options...
NaniG Posted February 3, 2012 Author Share Posted February 3, 2012 Yes, i confirmed Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1314083 Share on other sites More sharing options...
Maq Posted February 3, 2012 Share Posted February 3, 2012 NaniG, in the future, please place OR tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1314121 Share on other sites More sharing options...
Cobra23 Posted February 3, 2012 Share Posted February 3, 2012 Actually !! The host name is NOT the email address !! IT'S the mail server eg mail.mydomain.com Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1314129 Share on other sites More sharing options...
NaniG Posted February 6, 2012 Author Share Posted February 6, 2012 Thanks for the replies..! I changed the host name with $mail->Host = "mail.mydomain.com"; and am getting the same problem. Please help me out from these issue. Quote Link to comment https://forums.phpfreaks.com/topic/256283-smtp-error-could-not-connect-to-smtp-host-mailer-error-smtp-error-could-not/#findComment-1315092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.