I want to send email with all html using the gmail api. This is the preview of the html : https://docs.google.com/drawings/d/1J0nzeTol6VFr8sB1TlMDbTrSVanDncQ8FOelP_SvmY0/edit
But when i send the email to my test account and then i check the email in inbox all the styling in email is lost. This is the screenshot of the email after sending. https://docs.google.com/drawings/d/1yfzmlqzMhJMWbJth-o6mfgSJcGAtUIKr41hpvzlFQGE/edit?usp=sharing
I want to get the all the styling in emails. I have also tried the charset iso-8859-1 but still the same result.
This is my php code :
$service = new Google_Service_Gmail($this->client);
$user = 'me';
$strSubject = $subject;
$strRawMessage = "From: <".$from.">\r\n";
$strRawMessage .= "To: <".$to.">\r\n";
$strRawMessage .= 'Subject: =?utf-8?B?' . base64_encode($strSubject) . "?=\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 .= $message."\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.
$service->users_messages->send("me", $msg);
As the OP pointed out by changing Content-Transfer-Encoding: quoted-printable
to Content-Transfer-Encoding: base64
solves the problem.
I pretty much had the same problem and was able to solve it the same way
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With