我正在使用 gmail-api 向我的数据库中的不同联系人发送电子邮件。 当我发送消息时,样式不起作用,因为等号“=”丢失了。
比如在消息里放这个
<img src="mysite.com/image.jpg"/>
但是我把这个放在我放的地方=
<img src"mysite.com/image.jpg"/>
这是我为消息创建字符串的函数的一部分
$strSubject = $data['subject'];
//$strRawMessage = "From: myAddress<pblanco@mysite.com>\r\n";
$strRawMessage = "From: <".$data['from'].">\r\n"; //email consultor
//$strRawMessage .= "To: toAddress <pblanco@mysite.com>\r\n";
$strRawMessage .= "To: <".$data['to'].">\r\n"; //email destinatario
$strRawMessage .= 'Subject: =?utf-8?B?' . base64_encode($strSubject) . "?=\r\n"; //asunto
$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 .= $data['message']."\r\n"; //mensaje
// The message needs to be encoded in Base64URL
$msg = $this->createMessage($strRawMessage);
这里我对消息进行编码
public function createMessage($string){
//$mime = rtrim(strtr(base64_encode($string), '+/', '-_'), '=');
$mime = strtr(base64_encode($string), array('+' => '-', '/' => '_'));
$message = new Google_Service_Gmail_Message();
$message->setRaw($mime);
return $message;
}
我在我的函数 createMessage() 上尝试了不同的方法,但我仍然遇到这个问题。
最佳答案
由于您使用“quoted printable”作为内容编码,等号是转义字符,必须明确编码为 =3D
。
见:https://en.wikipedia.org/wiki/Quoted-printable
Any 8-bit byte value may be encoded with 3 characters: an = followed by two hexadecimal digits (0–9 or A–F) representing the byte's numeric value. For example, an ASCII form feed character (decimal value 12) can be represented by "=0C", and an ASCII equal sign (decimal value 61) must be represented by =3D. All characters except printable ASCII characters or end of line characters (but also =) must be encoded in this fashion.
关于php - 使用 gmail api 发送电子邮件时等号丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47175810/