Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php gmail api样式和图像省略,bcc标题显示时除外_Php_Gmail_Gmail Api - Fatal编程技术网

Php gmail api样式和图像省略,bcc标题显示时除外

Php gmail api样式和图像省略,bcc标题显示时除外,php,gmail,gmail-api,Php,Gmail,Gmail Api,我使用Gmail API和PHP在用户下单时从一个Gmail帐户向用户发送确认电子邮件。html正文和样式/图像不一致。对于在计算机上收到的每一封电子邮件(AIM、AOL、gmail或Gsuite地址),HTML的表格部分工作正常,但没有背景色、图像和居中。对于手机上发送给AIM的电子邮件,除了一个暴露的密件抄送字段(只有一次密件抄送被隐藏,并且样式和图像也丢失)外,我获得了所有样式和图像。在手机上,如果我查看收到(密件抄送)或发送的电子邮件,如果我登录到发送电子邮件的帐户,我可以看到电子邮件的

我使用Gmail API和PHP在用户下单时从一个Gmail帐户向用户发送确认电子邮件。html正文和样式/图像不一致。对于在计算机上收到的每一封电子邮件(AIM、AOL、gmail或Gsuite地址),HTML的表格部分工作正常,但没有背景色、图像和居中。对于手机上发送给AIM的电子邮件,除了一个暴露的密件抄送字段(只有一次密件抄送被隐藏,并且样式和图像也丢失)外,我获得了所有样式和图像。在手机上,如果我查看收到(密件抄送)或发送的电子邮件,如果我登录到发送电子邮件的帐户,我可以看到电子邮件的中心、图像和其他样式。当我尝试使用multipart/related和64位编码的图像时,我收到了一个带有很多图像代码的大附件,当我使用multipart/mixed时,我得到了相同的结果,但在消息体中。当我尝试使用外部64位编码图像时,消息太长。我只想发送带有链接图像的html,但我能找到的唯一关联是,图像和非表html格式仅在Bcc字段公开时显示。当我删除密件抄送字段时,我仍然收到带有表格的消息,但没有图像或其他样式。我不确定是我的消息太大还是发生了其他事情。发生了什么事?如何让html可靠地运行并包含图像?由于我的网站还不在公共服务器上,我使用了维基百科的占位符图像

我在的问题的一些例子没有足够的代表发布img

        $to_address = htmlspecialchars($order_row[0]['client_email']); 
        $to_name = htmlspecialchars($order_row[0]['client_name']); 
        $to_name = preg_replace("/[^A-Za-z0-9 ]/", '', $to_name);

        // // Subject
        $subject = 'Confimation for Order No. ' . $order_row[0]['order_number'];

        //optionals
        //delivery/pickup
        if ($order_row[0]["method"] == "delivery")
        {
            $pd_meth = "DELIVERY ADDRESS";
            $pd_line1 = htmlspecialchars($order_row[0]["client_address_1"]);
            $pd_line2 = htmlspecialchars($order_row[0]["client_address2"]);
            $pd_line3 = htmlspecialchars($order_row[0]["client_city"]) . ", FL " . htmlspecialchars($order_row[0]["client_zip"]);
            $pd_line4 = '<i>special instructions:</i>' . ' ' . htmlspecialchars($order_row[0]["special_instructions"]);
            $pd_message = "You selected to have your order delivered.";
        }
        else if ($order_row[0]["method"] != "delivery")
        {
            $pd_meth = "PICKUP PREFERENCE";
            $pd_line1 = $order_row[0]["pickup_window"];
            $pd_line2 = "<i>The pickup location is a home located in Sunset, FL near SW 72nd street and 107th ave.</i>";
            $pd_line3 = "<i>The detailed home address will be included in the email containing your specific pickup window.</i>";
            $pd_line4 = "";
            $pd_message = "You selected to pick up your order.";
        }
        //format phone no.
        if (strlen($order_row[0]["client_phone_number"]) == 10)
        {
            $form_phone = "(" . htmlspecialchars($order_row[0]["client_phone_number"][0]) . htmlspecialchars($order_row[0]["client_phone_number"][1]) . htmlspecialchars($order_row[0]["client_phone_number"][2]) . ") " . htmlspecialchars($order_row[0]["client_phone_number"][3]) . htmlspecialchars($order_row[0]["client_phone_number"][4]) . htmlspecialchars($order_row[0]["client_phone_number"][5]) . "-" . htmlspecialchars($order_row[0]["client_phone_number"][6]) . htmlspecialchars($order_row[0]["client_phone_number"][7]) . htmlspecialchars($order_row[0]["client_phone_number"][8]) . htmlspecialchars($order_row[0]["client_phone_number"][9]);
        }
        else if (strlen($order_row[0]["client_phone_number"]) > 10)
        {
            $form_phone = htmlspecialchars($order_row[0]["client_phone_number"]);
        }
        //cartrows/order_details
        $detail_table = "";
        //use var to count
            foreach ($order_det_rows as $order_det_row)
            {
                if ($order_det_row['flavor_2'])
                {
                    $detail_table .= "<tr><td>" . $order_det_row['price_cat'] . "</td><td>" . $order_det_row['flavor_1'] . "<hr>" . $order_det_row['flavor_2'] . "</td><td>" . $order_det_row['quantity'] . "<br/>" . $order_det_row['quantity2'] . "</td><td>$" . $order_det_row['price'] . "</td></tr>";
                }
                else
                {
                    $detail_table .= "<tr><td>" . $order_det_row['price_cat'] . "</td><td>" . $order_det_row['flavor_1'] . "</td><td>" . $order_det_row['quantity'] . "</td><td>$" . $order_det_row['price'] . "</td><td></tr>";
                }
            }
        //extras_added
        $extras_added_table = "";
        $ex_added = "no";
            foreach ($order_det_rows as $order_det_row)
            {
                if ($order_det_row['extra'] != "-")
                {
                    $extras_added_table .= "<table><tr><td>" . $order_det_row['price_cat'] . "</td><td> " . $order_det_row['flavor_1'] . " </td><td> + </td><td>" . $order_det_row['extra'] . "</td></tr></table>" ;
                    $ex_added = "yes";
                }
            }
            if ($ex_added == "no")
            {
                $extras_added_table = "<p>You did not add any extras.</p>";
            }
        //optional note
        $note = "";
        if($order_row[0]["note"])
        {
            $note .= '<h5> note: </h5><i>' . htmlspecialchars($order_row[0]["note"]). '</i><hr>';
        }

        // Message
        $mailbody = '
        <html>
        <head>
          <title>THANKS FOR YOUR ORDER</title>
        </head>
        <body style = "background-color:gray">
        <div align = "center" style = "background-color:white">
        <img alt="theglassoven" src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/04/Pound_layer_cake.jpg/220px-Pound_layer_cake.jpg" title = "header_logo" width="100%" height = "80" >
        <h2>THANKS FOR YOUR ORDER</h2>
            <p>ORDER NO. ' . $order_row[0]['order_number'] . '<br/>placed on: ' . $order_row[0]['time_of_order'] .'</p>
            <h4>**ORDER FOR ' . strtoupper($order_row[0]["method"]) .' ON '. $order_row[0]["order_date"] .'**</h4>
            <hr>
            <h4>YOUR INFORMATION</h4>
            <h5>DETAILS<h5/>
            <strong>name: </strong>
            ' . ' ' . htmlspecialchars($order_row[0]["client_name"]) . '<br/>
            <strong>phone number: </strong>
            ' . ' ' . $form_phone . '<br/>                
            <strong>email address: </strong>
            ' . ' ' . htmlspecialchars($order_row[0]["client_email"]) . '
            <br/>
            <h5>' . $pd_meth . '<h5/>
            ' . $pd_line1 .'<br/>
            ' . $pd_line2 . '<br/>
            ' . $pd_line3 . '<br/>
            ' . $pd_line4 . '<br/>

            <hr>
            <h4>YOU PURCHASED:</h4>
            <table>
                <tr>
                    <th>ITEM</th>
                    <th>FLAVOR</th> 
                    <th>QTY</th>
                    <th>PRICE</th>
                </tr>
                ' . $detail_table . '
            </table>
                <h5>subtotal: $' . $order_row[0]['cake_subtotal'] . '</h5>
            <hr>
            <h4>EXTRAS ADDED ?</h4>' . 
                $extras_added_table
            . ' <h5>add: $' . $order_row[0]['extra_total'] . '</h5>
            <hr>
            <h4>DELIVERY ?</h4>
            <p>' . $pd_message . '</p>
            <h5>add: $' . $order_row[0]['delivery_total'] . '</h5>
            <hr>
            <h4>TOTAL: $' . $order_row[0]['order_total'] . '</h4>
            <hr>' .
            $note
            .'
        <br/><i>As the date of your order approaches, you will recieve an email at <?=$order_row[0]["client_email"]?> with your delivery/pickup window.</i>
        <br/><br/><img alt = "logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/04/Pound_layer_cake.jpg/220px-Pound_layer_cake.jpg" width= "100" height = "100" title = "footer_logo"   />
        <br/>
        </div>
        </body>
        </html>
        ';

        $strSubject = "{$subject}";
        $strRawMessage = "From: The Glass Oven <email@gmail.com>\r\n";
        $strRawMessage .= "To: " . "{$to_name}" . "<" . "{$to_address}" . ">\r\n";
        $strRawMessage .= "Bcc: the glass oven<email@gmail.com>\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=iso-8859-1\r\n";
        $strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n";
        $strRawMessage .= $mailbody;
        // The message needs to be encoded in Base64URL
        $mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
        $message = new Google_Service_Gmail_Message();
        $message->setRaw($mime);


    define('APPLICATION_NAME', 'the glass oven');
    define('CREDENTIALS_PATH', '../gmail-php-quickstart.json');
    define('CLIENT_SECRET_PATH', '../client_secret.json');
    define('SCOPES', implode(' ', array(
        Google_Service_Gmail::GMAIL_SEND)
        ));

    function getClient() {
        $client = new Google_Client();
        $client->setApplicationName(APPLICATION_NAME);
        $client->setScopes(SCOPES);
        $client->setAuthConfig(CLIENT_SECRET_PATH);
        $client->setAccessType('offline');
        $accessToken = json_decode(file_get_contents('../gmail-php-quickstart.json'), true);
        $client->setAccessToken($accessToken);
        if ($client->isAccessTokenExpired()) {
            $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
            file_put_contents('../gmail-php-quickstart.json', json_encode($client->getAccessToken()));
          }
        return $client;
    }

    $userId = "me";
    $client = getClient();
    $service = new Google_Service_Gmail($client);

    function sendMessage($service, $userId, $message) {
        try {
            $message = $service->users_messages->send($userId, $message);
            //print 'Message with ID: ' . $message->getId() . ' sent.';
            return $message;
          } catch (Exception $e) {
            print 'An error occurred: ' . $e->getMessage();
          }
        }

    sendMessage($service, $userId, $message);
$to_address=htmlspecialchars($order_row[0]['client_email']);
$to_name=htmlspecialchars($order_row[0]['client_name']);
$to_name=preg_替换(“/[^A-Za-z0-9]/”,“”,$to_name);
////主题
$subject='订单号的确认'$订单行[0][“订单号”];
//期权
//交货/提货
如果($order_行[0][“方法”]=“交货”)
{
$pd_meth=“交货地址”;
$pd_line1=htmlspecialchars($order_row[0][“client_address_1]”);
$pd_line2=htmlspecialchars($order_row[0][“client_address2]”);
$pd_line3=htmlspecialchars($order_row[0][“client_city”])。,FL.htmlspecialchars($order_row[0][“client_zip”]);
$pd_line4='special instructions:'.'。.htmlspecialchars($order_row[0][“special_instructions”]);
$pd_message=“您已选择交付订单。”;
}
else if($order_行[0][“方法”!=“交货”)
{
$pd_meth=“取货优惠”;
$pd_line1=$order_行[0][“取货窗口”];
$pd_line2=“接送地点是位于佛罗里达州日落区西南72街和107大道附近的家”;
$pd_line3=“详细的家庭地址将包含在包含您特定取货窗口的电子邮件中。”;
$pd_line4=“”;
$pd_message=“您已选择提货。”;
}
//格式电话号码。
如果(strlen($order_row[0][“client_phone_number”])==10)
{
$form_phone=“(”.htmlspecialchars($order_row[0][“client_phone_number”][0]).htmlspecialchars($order_row[0][“client_phone_number”][1]).htmlspecialchars($order_row[0][“client_phone_number”][2])).htmlspecialchars($order_row[0][“client_phone_phone_number”][3]).htmlspecialchars($order_row[0][“client_phone_row[4]).htmlspecials])($order_row[0][“client_phone_number”][5])。“-”.htmlspecialchars($order_row[0][“client_phone_number”][6]).htmlspecialchars($order_row[0][“client_phone_number”][7]).htmlspecialchars($order_row[0][“client_phone_number”][8]).htmlspecialchars($order_row[0][“client_phone_phone_number”][9]);
}
else if(strlen($order_row[0][“client_phone_number]”)大于10)
{
$form_phone=htmlspecialchars($order_row[0][“client_phone_number]”);
}
//cartrows/订单详细信息
$detail_table=“”;
//使用var进行计数
foreach($order\u det\u行作为$order\u det\u行)
{
如果($order_det_row['flavor_2']))
{
$detail_table.=''.$order_det_row['price_cat'.''.'.$order_det_row['flavor_1'.''.“
”.$order_det_row['flavor_2'.'..$order_det row['quantity'.['quantity2'.$”.$order_det_row['price'.]; } 其他的 { $detail\U table.=''.$order\U det\U row['price\U cat'.'.'.$order\U det\U row['FANCE\U 1'.''.''.'.$order\U det\U row['QUOTE'.$”.$order\U det\U row['price'.]; } } //附加条款 $extras_添加了_table=“”; $ex_added=“否”; foreach($order\u det\u行作为$order\u det\u行) { 如果($order_det_row['extra']!=“-”) { $EXTRASS_添加了_表。=''.$order_det_行['price_cat']。''.$order_det_行['FANCE_1']。+“$order_det_行['extra']。”; $ex_added=“是”; } } 如果($ex_added==“no”) { $extras_added_table=“您没有添加任何额外内容。

”; } //可选注释 $note=“”; 如果($order_行[0][“note”]) { $note.='note:'.htmlspecialchars($order_行[0][“note”])。
; } //信息 $mailbody= 谢谢你的订单 谢谢你的订单 订单号.$ORDER\U row[0]['ORDER\U number'].
放在:'.$ORDER\U row[0]['time\U of\U ORDER'.'

**“$ORDER\U row[0][“ORDER\U date”]”上“.strtoupper($ORDER\U row[0][“方法”])”的订单**
你的信息 细节 <