php - How to send a reply to an mail using Gmail API -


i using gmail api send email .in sending done. want know how reply person ( send ) using php.

here attach code sending :

$line = "\n"; $strmailcontent = $message; $strmailtextversion = strip_tags($strmailcontent, '');  $strrawmessage = ""; $boundary = uniqid(rand(), true); $subjectcharset = $charset = 'utf-8';  $strtomail = $to;  $strsubject = $subject;  $strrawmessage .= 'to: ' . ($strtomail)  . "\r\n";  if(!empty($_post['cc']) || !empty($_post['bcc'])){     $cc = $_post['cc'];     $bcc = $_post['bcc'];     $strrawmessage .= "cc: $cc". $line;     $strrawmessage .= "bcc: $bcc". $line; }  $strrawmessage .= 'subject: =?' . $subjectcharset . '?b?' . base64_encode($strsubject) . "?=\r\n"; $strrawmessage .= 'mime-version: 1.0' . "\r\n"; $strrawmessage .= 'content-type: multipart/mixed; boundary="' . $boundary . '"' . "\r\n";    $filepath = $file_tmp_name; $mimetype =  'text/plain; charset="utf-8" '; $filename = $file_name; $filedata = base64_encode(file_get_contents($filepath));  $strrawmessage .= "\r\n--{$boundary}\r\n"; $strrawmessage .= 'content-type: '. $mimetype .'; name="'. $filename .'";' . "\r\n";             $strrawmessage .= 'content-description: ' . $filename . ';' . "\r\n"; $strrawmessage .= 'content-disposition: attachment; filename="' . $filename . '"; size=' . filesize($filepath). ';' . "\r\n"; $strrawmessage .= 'content-transfer-encoding: base64' . "\r\n\r\n"; $strrawmessage .= chunk_split(base64_encode(file_get_contents($filepath)), 76, "\n") . "\r\n"; $strrawmessage .= '--' . $boundary . "\r\n";    $strrawmessage .= $strmailcontent;  $mime = rtrim(strtr(base64_encode($strrawmessage), '+/', '-_'), '=');  $base64 = base64_encode($mime); $data = '{ "raw" : "'.$mime.'" }'; $send = qassim_http(1, $url, $header, $data); 

here pass address sended person mail id , subject used subject.

how change code send reply. please me

you need pass thread id of message want reply , set same subject new message. prefer using library generating raw string message, instead of writing manually in order minimize possibility of errors. below example using phpmailer.

$gmail = new google_service_gmail($client); $message = new google_service_gmail_message(); $optparam = array(); $referenceid = ''; $thread = $gmail->users_threads->get($userid, $threadid); $optparam['threadid'] = $threadid; $threadmessages = $thread->getmessages($optparam); $messageid = $threadmessages[0]->getid(); $messagedetails = $this->getmessagedetails($messageid); $messagedetails = $messagedetails['data']; $subject = $messagedetails['headers']['subject']; $mail = new phpmailer(); $mail->charset = 'utf-8'; $mail->from = $from_email; $mail->fromname = $from_name; $mail->addaddress($to); $mail->subject = $subject; $mail->body = $body; $mail->presend(); $mime = $mail->getsentmimemessage(); $raw = $this->base64urlencode($mime); $message->setraw($raw); $message->setthreadid($threadid); $response = $gmail->users_messages->send($userid, $message); 

userid id of logged in user, while threadid id of thread of message want reply to.

i've had lot of difficulties google's php sdk , lack of proper examples, wrote php wrapper covers of gmail api's functions. can find here, might useful.


Comments