Skip to content

Instantly share code, notes, and snippets.

@nczz
Last active August 26, 2019 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczz/dd8f7d264e660d4e8284c3d380266d59 to your computer and use it in GitHub Desktop.
Save nczz/dd8f7d264e660d4e8284c3d380266d59 to your computer and use it in GitHub Desktop.
使用 PHPMailer 解決輸出 MIME 格式的問題 https://www.mxp.tw/8635/
<?php
$service = new Google_Service_Gmail($client);
try {
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->From = "發信端信箱";
$mail->FromName = "發信端別名";
$mail->AddAddress("收信端信箱", "收信端別名");
$mail->AddReplyTo("回信端信箱", "回信端別名");
$mail->Subject = "信件主題";
$mail->Body = "信件內文";
$mail->isHTML(true);
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
$mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '=');
$mensaje = new Google_Service_Gmail_Message();
$mensaje->setRaw($mime);
$service->users_messages->send('me', $mensaje);
} catch (Exception $e) {
print($e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment