Sending HTML via PEAR using SMTP authentication returns an error

I am trying to send an HTML message when using SMTP authentication in Gmail in PHP. Here is the script I'm using:

require_once "Mail.php";
require_once 'Mail/mime.php';

$from = "Some Name <myemail@gmail.com>";
$to = "Other Name <otheremail@gmail.com>";
$subject = "This is a test";
$crlf = "\n";

$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "myemail@gmail.com";
$password = "mypass";

$headers = array ('From' => $from,
                  'Return-Path' => $from,
                  'Subject' => $subject);

$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mime = new Mail_mime($crlf);
$mime->setTXTBody("This is a test email message");
$mime->setHTMLBody($body);
$body = $mime->get();
$headers = $mime->headers($headers);

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {
  echo("<p>Message successfully sent!</p>");
}

Note. $bodyis an HTML table with images and other information.

When I execute the script, it fails with the following error:

Failed to set the sender: Some name [SMTP: invalid response code received from the server (code: 555, response: 5.5.2 Syntax error. C6sm20541406obd.22)]

Here is what I was trying to understand what is going wrong: 1. Using the same script, using "Mail" instead of "smtp" ie

$smtp = Mail::factory('Mail');

. 2. script mime.php, , HTML-.

- , , - SMTP HTML?

EDIT: $mime->headers():

[MIME-Version] => 1.0
[From] => Some Name
[Return-Path] => Some Name
[Subject] => This is a test
[Content-Type] => multipart/alternative;
boundary="=_8662996a1f586248545d9f01f48e916d"
+5
4
0

. URL. , .

HTML- SMTP PHP

SMTP- Gmail SMTP.GOOGLEMAIL.COM SMTP.GMAIL.COM.

:

// ...
$smtp=array();
$smtp['host']='ssl://smtp.googlemail.com';

. : -

HTML SMTP- PHP PEAR

http://tonyvirelli.com/slider/php-html-email-using-smtp/

+2

, :

$from = '"Some Name" <myemail@gmail.com>';
$to = '"Other Name" <otheremail@gmail.com>';

.

:
, , , php- smtp gmail.

:

$host = "tls://smtp.gmail.com";
$port = "587";

, gmail phpmailer.

+1

, (. ). , 11/2/2017. . , , < 5 , 2-. .

Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Invalid response code received from server (code: -1, response: )]
fsockopen(): Failed to enable crypto
fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

( ..)

, , Google, :

$result = fsockopen('ssl://smtp.gmail.com', 465, $error_no,
$error_message, 5);     
if($result === false) {         
    echo "error no:
$error_no error message: $error_message";       echo print_r($result,true);     
}else{      
    echo 'success\n\n';
}

, CA, PHP Google:

0
source

All Articles