How do I send email using gmail api php

后端 未结 3 1851
-上瘾入骨i
-上瘾入骨i 2021-01-03 17:22

How do I send email using gmail api php

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


        
3条回答
  •  借酒劲吻你
    2021-01-03 17:31

    Swiftmailer has all the tools for building base64 message.

    Here is a full sample for sending a email:

    // Visit https://developers.google.com/gmail/api/quickstart/php
    // for an example of how to build the getClient() function.
    $client = getClient();
    
    $service = new \Google_Service_Gmail($client);
    $mailer = $service->users_messages;
    
    $message = (new \Swift_Message('Here is my subject'))
        ->setFrom('myemailaddress@myserver.com')
        ->setTo(['receiver@someserver.com' => 'Test Name'])
        ->setContentType('text/html')
        ->setCharset('utf-8')
        ->setBody('

    Here is my body

    '); $msg_base64 = (new \Swift_Mime_ContentEncoder_Base64ContentEncoder()) ->encodeString($message->toString()); $message = new \Google_Service_Gmail_Message(); $message->setRaw($msg_base64); $message = $mailer->send('me', $message); print_r($message);

提交回复
热议问题