PHP Send error message

Please help me, I'm new to PHP, and since the last 5 hours I have been trying to send mail and am now really tired. Thanks.

Here is my code. I am using a Gmail account.  

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

$mail             = new PHPMailer();

$body             = $mail->getFile('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP();
$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   = "hussaintalha@gmail.com";  // GMAIL username
$mail->Password   = "xxxxxxxx";            // GMAIL password

$mail->AddReplyTo("hussaintalha@gmail.com","First Last");

$mail->From       = "hussaintalha@gmail.com.com";
$mail->FromName   = "First Last";

$mail->Subject    = "PHPMailer Test Subject via gmail";

//$mail->Body       = "Hi,<br>This is the HTML BODY<br>";                      //HTML Body
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddAddress("hussaintalha@gmail.com", "John Doe");

$mail->AddAttachment("images/phpmailer.gif");             // attachment

$mail->IsHTML(true); // send as HTML

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

When I run my file, I get this error:

Warning: fopen (contents.html) [function.fopen]: could not open stream: there is no such file or directory in D: \ xampplite \ HTDOCS \ WebEng \ class.phpmailer.php on line 1870

Warning: fsockopen () [function.fsockopen]: cannot connect to ssl: //smtp.gmail.com: 465 (Can't find ssl socket transport - did you forget to enable it when you configured PHP?) In D: \ xampplite \ HTDOCS \ WebEng \ class.smtp.php on line 122 Mailer Error: SMTP Error: Failed to connect to the SMTP host.

+3
2

, , ! 90% , , .

, 1 , , google . , , .

. xampp light SSL. , sendmail. , . , , , - . , , ..

, , :

<?php

include("class.phpmailer.php");

$mail             = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "hussaintalha@gmail.com";  // GMAIL username
$mail->Password   = "xxxxxxxx";            // GMAIL password

$mail->From       = "hussaintalha@gmail.com";
$mail->Subject    = "PHPMailer Test Subject via gmail";
$mail->Body       = "Hi, this is a test";           
$mail->AddAddress("hussaintalha@gmail.com", "Hussain");

$mail->send();
?>

oh btw. .com !

+4

PHP (XAMPP, ) SSL. ,

extension=php_openssl.dll

php.ini, Apache, , ( ) ssleay32.dll libeay32.dll PHP Apache binary (.exe), Apache.

+4

Source: https://habr.com/ru/post/1706200/


All Articles