如何在电子邮件中使用非ascii字符串在PHP主题:,to:等



请告诉我,我使用curl发送php电子邮件(gmail api)。内容类型为message/rfc822。在发送电子邮件时,如何在主题中使用西里尔字母?在信的主体中,西里尔字母是正常显示的,在信的主体中,它是作为符号显示的。ÐÿN€Ð¸Ð²ÐµN .

$access_token = "***";
$message = "To: ".addslashes($_POST['to'])."rnSubject: ".addslashes($_POST['subject'])."rnrn".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");

最新更新