2017-01-10 22 views
1

Gmail APIを使用してPHPからHTML埋め込みメールを送信する際に問題があります。Gmail APIを使用してPHPからメールを送信

ここでは、コードです:

$raw_message .= "To:".$email['name']." <".$email['email'].">\r\n"; 
$raw_message .= 'Subject: =?utf-8?B?' .base64_encode($email_array['subject']) . "?=\r\n"; 

// Set the right MIME & Content type 
$raw_message .= "MIME-Version: 1.0\r\n"; 
$raw_message .= "Content-Type: text/html; charset=utf-8\r\n"; 
$raw_message .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n"; 

$mime = rtrim(strtr(base64_encode($raw_message), '+/', '-_'), '='); 
$message = new Google_Service_Gmail_Message(); 
$message->setRaw($mime); 

$template = $this->load->view('email/default_email_template', $email_template_array, true); 
$raw_message .= $template; 

$mime = rtrim(strtr(base64_encode($raw_message), '+/', '-_'), '='); 
$message = new Google_Service_Gmail_Message(); 
$message->setRaw($mime); 

$response = $service->users_messages->send($user, $message); 

私が受け取る電子メールはテキストだけですが。

ここでいくつかのヘルプを使用することができます。

ありがとうございます!

編集:ここに私のテンプレートは、あなたがPHPを使用してメッセージを送信する方法で、このtutorialをチェックしようとすることができます

<body style="height: 100% !important; margin: 0 !important; padding: 0 !important; width: 100% !important;margin: 0 !important; padding: 0 !important;"> 

<!-- HEADER --> 
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse !important;"> 
<tr> 
<td bgcolor="#fff" align="center"> 
<!--[if (gte mso 9)|(IE)]> 
<table align="center" border="0" cellspacing="0" cellpadding="0" width="500"> 
<tr> 
     <td align="center" valign="top" width="500"> 
     <![endif]--> 
     <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse !important;max-width: 500px;width: 100% !important; max-width: 100% !important;"> 
      <tr> 
       <td align="center" valign="top" style="padding: 15px 0;margin: 0 auto !important;" class="logo"> 
        <a href="https://www.example.com" target="_blank"> 
         <img alt="Logo" src="https://example.com/home/images/logo.png" width="90" height="90" style="border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; display: block; font-family: Helvetica, Arial, sans-serif; color: #ffffff; font-size: 16px;" border="0"> 
        </a> 
        <span style="font-size: 40px; color: #000000;">mad</span><span style="font-size: 40px; color: #e18a07;">gigs</span> 
       </td> 
      </tr> 
     </table> 
     <!--[if (gte mso 9)|(IE)]> 
     </td> 
     </tr> 
     </table> 
     <![endif]--> 
    </td> 
</tr> 
<tr> 
    <td bgcolor="#ffffff" align="center" style="padding: 0px 15px 20px 15px;padding: 50px 15px 50px 15px !important;" class="section-padding"> 
     <table border="0" cellpadding="0" cellspacing="0" width="500" class="responsive-table" style="border-collapse: collapse !important;width: 100% !important;"> 
      <tr> 
       <td> 
        <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse !important;"> 
         <tr> 
          <td> 
           <!-- COPY --> 
           <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse !important;"> 
            <tr> 
             <td align="center" style="font-size: 25px; font-family: Helvetica, Arial, sans-serif; color: #333333; padding-top: 30px;padding: 10px 5% 10px 5% !important;text-align: center" class="padding-copy">HI THERE</td> 
            </tr> 
            <tr> 
             <td align="center" style="padding: 20px 0 0 0; font-size: 16px; line-height: 25px; font-family: Helvetica, Arial, sans-serif; color: #666666;padding: 10px 5% 10px 5% !important;text-align: center;" class="padding-copy">BODY OF THE EMAIL</td> 
            </tr> 
           </table> 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
     </table> 
    </td> 
</tr> 
<tr> 
    <td bgcolor="#ffffff" align="center" style="padding: 20px 0px;"> 
     <!--[if (gte mso 9)|(IE)]> 
     <table align="center" border="0" cellspacing="0" cellpadding="0" width="500"> 
     <tr> 
     <td align="center" valign="top" width="500"> 
     <![endif]--> 
     <!-- UNSUBSCRIBE COPY --> 
     <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" style="border-collapse: collapse !important; max-width: 500px;width: 100% !important;" class="responsive-table"> 
      <tr> 
      </tr> 
     </table> 
     <!--[if (gte mso 9)|(IE)]> 
     </td> 
     </tr> 
     </table> 
     <![endif]--> 
    </td> 
</tr> 
<tr> 
    <td bgcolor="#DFE4E6" align="center" style="padding: 20px 0px;"> 
     <!--[if (gte mso 9)|(IE)]> 
     <table align="center" border="0" cellspacing="0" cellpadding="0" width="500"> 
     <tr> 
     <td align="center" valign="top" width="500"> 
     <![endif]--> 
     <!-- UNSUBSCRIBE COPY --> 
     <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" style="border-collapse: collapse !important;max-width: 500px;width: 100% !important;" class="responsive-table"> 
      <tr> 
       <td align="center" style="font-size: 12px; line-height: 18px; color:#666666;"> 

       </td> 
      </tr> 
     </table> 
     <!--[if (gte mso 9)|(IE)]> 
     </td> 
     </tr> 
     </table> 
     <![endif]--> 
    </td> 
</tr> 

+0

電子メール/ default_email_templateコードを共有してください。あなたはCSSのクラスを使用していますか? – Ruby

+0

こんにちは、私は認証/送信プロセス全体のソースコードに興味があります。何とか話せますか? –

答えて

0

です。電子メール本文にHTMLコンテンツを送信する方法をここで学びますが、これはさまざまな方法で実現できます。

は、これらの2は、一般的に使用されています

  1. PHPの作り付けのメール()」関数を使用します。
  2. 'PHPMailer'ライブラリを使用しています。

チュートリアルで必要な手順と、ガイドとなるサンプルコードを確認してください。詳細については

、これらのスレッドをチェック:メール/ default_eを設計する

+0

あなたの答えをありがとう、しかし、私が言及したように、私は彼のGmailアカウントから電子メールを送信するために私のWebアプリケーションを認証するユーザーを認証しています。だから私が送ることができる唯一の方法は、Googleライブラリの "Send"関数(私が間違っていれば、私を修正してください)です。私は 'base_64'をエンコードするので、HTMLタグをすべて取り除いています。私はそれをしないでメールを送る別の方法があるかどうかを知る必要があります! 私のユーザーが受け取ったメールをさらに取得するために、Googleからmessage_ids&thread_idsを保存する必要があるため、SMTPを使用できません。 – user3523750

0

使用インラインスタイルをmail_templateページ。 CSSクラスは使用しないでください。クラスを使用すると、デザインはOutlookや他の電子メールサービスツールに表示されます。しかし、Gmailではそうではありません。 gmailはCSSクラス名にプレキャラクタを追加するためです。

+0

私の編集をご覧ください! – user3523750

0

これについて数時間の研究をした後、私はそれを最終的に理解しました。 生メッセージのcharsetは、Content-Type: text/html; charset=iso-8859-1 &ではなく、utf-8に設定する必要があります。

ここでこのトピックの詳細 -

Stackoverflow answer on the difference between UTF-8 and ISO-8859-1

Original article from Wikipidea on ISO-8859-1

は今、私のメールがタクトにすべてのスタイルと付き合っています。異なるクライアントにチェックインされた場合、&それはすべてで完全に正常に動作します!