gpt4 book ai didi

gmail-api - 如何使用 gmail api php 发送电子邮件

转载 作者:行者123 更新时间:2023-12-05 08:13:32 29 4
gpt4 key购买 nike

我如何使用 gmail api php 发送电子邮件

$msg['raw'] = "This is sample test message";            
$msg['To'] = "test.api@gmail.com";
$msg['subject'] = "Sample test subject";

目前我正在使用 $message = $service->users_messages->send('me', $msg);

在哪里定义,subject ?

最佳答案

基于 http://www.pipiscrew.com/2015/04/php-send-mail-through-gmail-api/这是答案:

$user = 'me';
$strSubject = 'Test mail using GMail API' . date('M d, Y h:i:s A');
$strRawMessage = "From: myAddress<myemail@gmail.com>\r\n";
$strRawMessage .= "To: toAddress <recptAddress@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=utf-8\r\n";
$strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n\r\n";
$strRawMessage .= "this <b>is a test message!\r\n";
// The message needs to be encoded in Base64URL
$mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
$msg = new Google_Service_Gmail_Message();
$msg->setRaw($mime);
//The special value **me** can be used to indicate the authenticated user.
$service->users_messages->send("me", $msg);

关于gmail-api - 如何使用 gmail api php 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24606988/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com