繁体   English   中英

如何在 PHP 中的电子邮件主题:、收件人:等中使用非 ASCII 字符串

[英]How to use non-ASCII strings in email Subject:, To: etc in PHP

请告诉我,我使用 curl php 电子邮件(gmail api)发送。 内容类型是消息/rfc822。 发送时如何在电子邮件的主题中使用西里尔字母。 在字母的正文中,西里尔字母正常显示,在字母的主题中显示为符号。 ПривеÑ。

$access_token = "***";

$message = "To: ".addslashes($_POST['to'])."\r\nSubject: ".addslashes($_POST['subject'])."\r\n\r\n".addslashes($_POST['message']);

$ch = curl_init('https://www.googleapis.com/upload/gmail/v1/users/me/messages/send'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token, 'Accept: application/json', 'Content-Type: message/rfc822; charset=utf-8'));    
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
$data = curl_exec($ch);

您需要使用标准的 php 函数:

mb_encode_mimeheader($_POST['subject'], "UTF-8");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM