generate functionMon, 02 Jan 2023

send email with google client php sdk

function send_email($subject, $body) { $client = new Google_Client(); $client->setAuthConfig('credentials.json'); $client->addScope(Google_Service_Gmail::GMAIL_SEND); $client->setAccessType("offline"); $client->setApprovalPrompt("force"); $service = new Google_Service_Gmail($client); $email = new Google_Service_Gmail_Message(); $string = "From: noreply@example.com\r\n"; $string .= "Content-type: text/html;charset=iso-8859-1\r\n"; $string .= "Subject: $subject\r\n"; $string .= "$body\r\n"; $email->setRaw($string); $service->users_messages->send('me', $email); } send_email('subject', 'body');

Questions about programming?Chat with your personal AI assistant