如何将 Gmail 操作按钮添加到代码点火器的电子邮件库中


How to add Gmail action buttons to codeigniter's email library?

我正在尝试在从codeigniter的电子邮件库发送电子邮件时嵌入gmail操作按钮。我的邮件看起来像这样 -

     $this->email->from('mail@mysite.com', 'MyName');
     $this->email->to('user@yoursite.com');
     $this->email->set_mailtype("html");
     $this->email->subject('Testing action');
     $msg = '<html>
    <body>
    <script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "EmailMessage",
  "action": {
    "@type": "ViewAction",
    "url": "https://watch-movies.com/watch?movieId=abc123"
  },
  "description": "Watch the Avengers movie online"
}
</script>
    <div>EMAIL CONTENT GOES HERE</div>
    </body>
    </html>';
    $this->email->message($message);

在此之后,我将发送邮件。它只发送<div>EMAIL CONTENT GOES HERE</div>部分。不会生成任何操作按钮。我什至尝试使用Google开发人员页面中提供的微数据。什么都没用。知道这里出了什么问题吗?

首先,您似乎使用了错误的变量$message而不是$msg

除此之外,我认为 condeigniter 正在逃避您的代码。看看_prep_quoted_printable函数。

我建议你使用微数据方法:https://developers.google.com/gmail/actions/reference/formats/microdata

从示例中:

<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://watch-movies.com/watch?movieId=abc123"/>
  </div>
  <meta itemprop="description" content="Watch the 'Avengers' movie online"/>
</div>

另外,不要忘记您必须在Google注册您的操作:http://developers.google.com/gmail/actions/registering-with-google