/** * send gmail * * TODO: 請加入附件, 但應該不是在這個 method 擴充 * * @return boolean */ public static function sendMessage($from, $to, $subject, $body) { $mail = new \Nette\Mail\Message(); $mail->setFrom($from)->addTo($to)->setSubject($subject)->setBody($body); $messageText = $mail->generateMessage(); $data = self::_encodeRawData($messageText); try { $message = new Google_Service_Gmail_Message(); $message->setRaw($data); self::getService()->users_messages->send("me", $message); } catch (Exception $e) { echo 'Send message error ' . $e->getMessage() . "\n"; return false; } return true; }