php - 使用 gmail php api 发送带有所有样式的 Html 内容的电子邮件

标签 php gmail-api

我想使用 gmail api 发送包含所有 html 的电子邮件。
这是 html 的预览:
https://docs.google.com/drawings/d/1J0nzeTol6VFr8sB1TlMDbTrSVanDncQ8FOelP_SvmY0/edit

但是当我将电子邮件发送到我的测试帐户然后我在收件箱中检查电子邮件时,电子邮件中的所有样式都丢失了。
这是邮件发送后的截图。
https://docs.google.com/drawings/d/1yfzmlqzMhJMWbJth-o6mfgSJcGAtUIKr41hpvzlFQGE/edit?usp=sharing

我想获得电子邮件中的所有样式。
我也尝试过字符集 iso-8859-1,但结果仍然相同。

这是我的 php 代码:

        $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);

最佳答案

正如OP通过更改Content-Transfer-Encoding: quoted-printable所指出的那样至 Content-Transfer-Encoding: base64解决了这个问题。

我几乎遇到了同样的问题,并且能够以同样的方式解决它

关于php - 使用 gmail php api 发送带有所有样式的 Html 内容的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47430798/

相关文章:

php - 发送自定义数据的 Apple 推送通知

php - 跟踪在 gMail 中打开的电子邮件

javascript - 在 Javascript 中解析 Gmail 批处理响应

go - 如何通过 Gmail Go SDK 将 html 模板正文作为电子邮件发送?

php - 如何修复代码中 undefined variable 行

php - Symfony 2 : Swiftmailer not sending, 没有错误

php - 为什么 PHP 错误会打印两次?

php - 如何使用 Guzzlehttp/guzzle 6 发送 Cookie?

python - Gmail 邮件正文的编码是什么?如何解码?

node.js - gcloud pubsub - 如何创建监视请求