0

I am working on a webmail in which i am using phpmailer class .The problem is i am getting the error "SMTP Error: Could not connect to SMTP host. Message was not sent PHP Mailer Error: SMTP Error: Could not connect to SMTP host."

my code is :

 <html>
<head>
<title>PHPMailer - SMTP basic test with authentication</title>
</head>
<body>

<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

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

$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->Mailer = 'smtp';
$mail->SMTPSecure = 'ssl';

$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "mypass";

$mail->SingleTo = true; // if you want to send mail to the users individually so that no recipients can see that who has got the same email.

$mail->From = "[email protected]";
$mail->FromName = "mypass";

$mail->addAddress("[email protected]","User 1");
$mail->addAddress("[email protected]","User 2");

$mail->addCC("[email protected]","User 3");
$mail->addBCC("[email protected]","User 4");

$mail->Subject = "Testing PHP Mailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";

if(!$mail->Send())
    echo "Message was not sent <br />PHP Mailer Error: " . $mail->ErrorInfo;
else
    echo "Message has been sent";

?>

</body>
</html>

And my php.ini setting is :

    [mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port = 465

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path ="C:\wamp\sendmail\sendmail.exe -t -i"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;

would someone like to let me know that where i am wrong , I need your kind attention at this problem.

2 Answers 2

2

Try replacing

 $mail->SMTPSecure = 'ssl';

By

$mail->SMTPSecure = 'tls';
1
  • i have replaced it,its takes time in browsing and then i page goes blank.Does it mean the code is executed successfully ? because else echo "Message has been sent"; does show the message Commented Jun 15, 2013 at 8:22
0

your smtp host was set correct but then your $mail->Mailer = 'smtp'; should be $mail->Mailer = 'mail'; unless you had your own smtp server to send direct smtp?.. i'm not quite sure but i've experienced it dude... ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.