Search code examples
phpgmail

unable to connect while sending the mail in php using the PHP mailer


I downlaoded a mailer file from https://github.com/PHPMailer/PHPMailer and tried to used in my program to send email, but it lead me to some error . first let have a look at the code

include 'PHPMailer-master/class.phpmailer.php';
include 'PHPMailer-master/class.smtp.php';

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "*****";
$mail->SetFrom('[email protected]');
$mail->Subject = "Test";
$mail->Body = "this the mail for subscription";
$mail->AddAddress('[email protected]');
 if(!$mail->Send())
 {
     echo "Mailer Error: " . $mail->ErrorInfo;
 }
 else
 {
     echo "Message has been sent";
 }
?>

after running this code i get the error message as:

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1546610735)SMTP Connect() failed. Mailer Error: SMTP Connect() failed.

please let me know the problem, as i have seen other post...but i did not get any hint


Solution

  • Just replace

    $mail->Host = 'smtp.gmail.com';
    

    No need to specify the SSL here.