1

SMTP Error: Could not connect to SMTP host.
can some one check if i doing this right?

 $mail = new PHPMailer();
                    $mail->IsSMTP(); 
                    $mail->Mailer = "smtp";
                    $mail->Host = " smtp.gmail.com";
                    $mail->SMTPAuth = true;
                    $mail->SMTPSecure = "ssl";  //ssl or tls

                    //$mail->Host = "ssl://smtp.gmail.com";                         
                    $mail->Port = 465;              //set smtp port for the gmail
                    $mail->Username = "test1@gmail.com";    //yourname@yourdomain
                    $mail->Password = "asdfasdf";     //password

                    //to
                    $mail->AddAddress("test2@hotmail.com"); //to:   
                    //subject
                    $mail->Subject = "tttt";
                    //html body
                    $mail->IsHTML(true);
                    $mail->Body = "HEllow ikhlas";
                    //from
                    $mail->From = "test1@gmail.com";
                    $mail->FromName = "test";
                    $mail->wordWrap = 50;
                    //send
                    if(!$mail->send())
                    {
                        $forgot_error .= "Mail error ".$mail->ErrorInfo;
                    }
                    else
                    {
                        $forgot_error .= "E-mail has be sent to <b>$email_f</b>";
                    }
3
Contributors
16
Replies
42
Views
5 Years
Discussion Span
Last Post by vibhaJ
Featured Replies
  • 1

    Yes. Search this forum. This has been discussed a lot of times. IIRC the ssl port is 995, but not 100% sure. Read More

  • 1

    You have blank space in host name. Also add `$mail->SMTPDebug = 2; ` in your code for debugging. $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // … Read More

  • 1

    Code i have tried: <html> <head> <title>PHPMailer - SMTP (Gmail) basic test</title> </head> <body> <?php error_reporting(E_STRICT); date_default_timezone_set('America/Toronto'); require("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $body = "this is <strong>testing</strong> mail ". date('Y-m-d H:i:s'); $mail->IsSMTP(); // telling the class to use SMTP $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // … Read More

  • 1

    You need to enable OpenSSL extension. Edit your php.ini file and remove comma in front of openssl. **extension=php_openssl.dll** Read More

  • 1

    Add below code in test.php file and run it in browser, you will see all PHP configuration. <?php phpinfo(); phpinfo(INFO_MODULES); ?> Now look into **Loaded Configuration File** , it will show php.ini file path. Read More

1

Yes. Search this forum. This has been discussed a lot of times. IIRC the ssl port is 995, but not 100% sure.

0

i tried searching for it but all i keep on finding is phpmailer functions and example of how to use them.
do u happen to remember what are the gmail setting?

on my gmail i did change IMAP to enabled

Edited by hwoarang69

1

You have blank space in host name.

Also add $mail->SMTPDebug = 2; in your code for debugging.

$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
Votes + Comments
1

Code i have tried:

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>
<?php
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');
require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();

$body = "this is <strong>testing</strong> mail ". date('Y-m-d H:i:s');

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "****@***.com";  // GMAIL username
$mail->Password   = "*****";            // GMAIL password

$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);

$address = "youraddress@test.com"; // add your address here 
$mail->AddAddress($address, "Gmail Test");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>
</body>
</html>
Votes + Comments
0
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (32) 
SMTP Error: Could not connect to SMTP host.

so wired i have same as you still 




    $mail = new PHPMailer();
                        $mail->IsSMTP(); 
                        $mail->SMTPDebug  = 2; 
                        $mail->Mailer = "smtp";
                        $mail->Host = "smtp.gmail.com";
                        $mail->SMTPAuth = true;
                        $mail->SMTPSecure = "ssl";  //ssl or tls                        
                        $mail->Port = 465;              //set smtp port for the gmail
                        $mail->Username = "sender@gmail.com";    //yourname@yourdomain
                        $mail->Password = "*******";     //password

                        //to
                        $mail->AddAddress("reserver@hotmail.com"); //to:    
                        //subject
                        $mail->Subject = "test1";
                        //html body
                        $mail->IsHTML(true);
                        $mail->Body = "HEllow ";
                        //from
                        $mail->From = "sender@gmail.com";
                        $mail->FromName = "test";
                        $mail->wordWrap = 50;
                        //send
                        if(!$mail->send())
                        {
                        }
                        else
                        {
                        }

Edited by hwoarang69

1

You need to enable OpenSSL extension.
Edit your php.ini file and remove comma in front of openssl.

extension=php_openssl.dll

Edited by vibhaJ

Votes + Comments
0

where do i put php.ini file and do i include in my code?

and what is extension=php_openssl.dll

sorry for asking to many question but this is my first time doing this

Edited by hwoarang69

1

Add below code in test.php file and run it in browser, you will see all PHP configuration.

<?php
phpinfo();
phpinfo(INFO_MODULES);
?>

Now look into Loaded Configuration File , it will show php.ini file path.

Votes + Comments
0

i found php.ini file but there is no openssl.dll

Edited by hwoarang69

1

I forget to tell you, if you do any changes in php.ini file, you need to restart your server to see changes.

Votes + Comments
so happy this works!
0

there is no extension=php_openssl.dll in my php.ini file.
xampp->php->php.ini

Edited by hwoarang69

1

It should be. I think just before few mins you have post all extensions from php.ini and it was there,
Even when you check php configuration from browser (from test.php and code which i have posted above), you will see box for "openssl".

Votes + Comments
0

in my php.ini there is no openssl. so i download another one from online which had openssl.

so i del my old php.ini and add the new php.ini.
but then i cant start my apache.
only way i can start my apache if i add my old php.ini file which dont have openssl.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.