I'm using Google oAuth2 to authenticate my client then sending emails on their behalf using Zend (v1.12) SMTP, all using PHP. My question is how do I include the client's default email signature (as set in their Gmail settings) on the outgoing mail created using Zend?
I have full access to the client's Gmail so hoping there is a way to get their HTML signature and then add it to my html email body. Something like this:
...
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$obj=json_decode($_SESSION["access_token"],true);
$client_token=$obj['access_token'];
require_once 'Zend/Mail/Transport/Smtp.php';
require_once 'Zend/Mail.php';
$email = 'ClientJohn@abcco.com';//uses gmail business app
$token = $client_token;
$initClientRequestEncoded = base64_encode("user={$email}\1auth=Bearer {$token}\1\1");
$config = array('ssl' => 'ssl', 'port' => '465', 'auth' => 'oauth2', 'xoauth2_request' => $initClientRequestEncoded);
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$mail = new Zend_Mail();
// Not real code:
$signature=$_GET['client HTML signature'];
//
$mail->setBodyText('EMAIL_BODY'.$signature);
$mail->setBodyHtml('<b>EMAIL</b>_BODY'.$signature);
$mail->setFrom('ClientJohn@abcco.com', 'Client John');
$mail->addTo('michaelt@test.com', 'Michael F');
$mail->setSubject('EMAIL_SUBJECT');
$mail->send($transport);
} else {
$authUrl = $client->createAuthUrl();
}
...
I've reviewed the Gmail rest API (https://developers.google.com/gmail/api/) which doesn't say anything about signatures.
I've searched the web and reviewed numerous questions on Stack Overflow like: How to send an email in C# with gmail template/signature but don't think this works as I'm not creating the signature, just want to get what the client already uses. This is promising, just not sure how to implement it into my code (as it's using codeigniter): How can add email signature in codeigniter? Most of the web searches are about the digital signature of the email. I'm looking for the actual HTML signature at the bottom of the email I create.
If there isn't a way to get it from Gmail I'm thinking I'll have to have each client send me an email, copy and paste their signature HTML string into a database, then will have to pull that HTML for every email based on the user...not ideal because if they change their signature they'll also have to tell me so I can update the DB.