Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GMAIL API removes my html attributes when sending

Tags:

gmail

THE SITUATION:

What is this question all about and what am I doing?

I am sending electronic mails (e-mails) with PHP GMAIL-API.

How is it that I am sending e-mails?

$contenido="Whatever <span style="color:green;">and</span> then img <img src='#' ... >";    

$strRawMessage = "From: Flauta <[email protected]>\r\n";
$strRawMessage .= "To: <".$paquien.">\r\n";
$strRawMessage .= 'Subject: =?utf-8?B?' . base64_encode($sujeto) . "?=\r\n";
$strRawMessage .= "MIME-Version: 1.0\r\n";
$strRawMessage .= "Content-Type: text/html; charset=utf-8\r\n";
$strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n";
$strRawMessage .= $contenido."\r\n";


// The message needs to be encoded in Base64URL
$mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
$msg = new Google_Service_Gmail_Message();
$msg->setRaw($mime);

//The special value **me** can be used to indicate the authenticated user.
$objSentMsg = $service->users_messages->send("me", $msg);

echo 'Awesome.... stuff was sent.';

Are the e-mails actually being sent?

Yes.

But this flowy stuff removing the image... and I do not know why.

What am I receiving?

In the mail i receive i just get plain tags without attributes.

In this case: Whatever <span>and</span> then img <img>

Do you know if I need to encode the content in any other special way or something?

It is my fault because I am doing it wrong.

But it is not my fault not to know what I am doing wrong.

So there is no fault at all.

Who was talking about fault anyways?

like image 872
Gambler Twice Avatar asked Sep 15 '25 10:09

Gambler Twice


1 Answers

Try

$strRawMessage .= 'Content-Transfer-Encoding: base64' . "\r\n\r\n";

instead of

$strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n";
like image 133
Dens Avatar answered Sep 17 '25 21:09

Dens