Example #1
0
 /**
  * TODO support HTML emails
  * @return the sent message ID
  * @throws MailerException if the mail could not be immediately sent
  */
 static function phpmailer($to, $to_name, $subject, $message, $html_message = false)
 {
     $mail = new \PHPMailer();
     $mail->IsSMTP();
     // set mailer to use SMTP
     $mail->Host = \Openclerk\Config::get('phpmailer_host');
     // specify main and backup server
     $mail->SMTPAuth = true;
     // turn on SMTP authentication
     $mail->Username = \Openclerk\Config::get('phpmailer_username');
     // SMTP username
     $mail->Password = \Openclerk\Config::get('phpmailer_password');
     // SMTP password
     $mail->From = \Openclerk\Config::get('phpmailer_from');
     $mail->FromName = \Openclerk\Config::get('phpmailer_from_name');
     $mail->Sender = \Openclerk\Config::get('phpmailer_from');
     $mail->AddAddress($to, $to_name);
     if (\Openclerk\Config::get('phpmailer_reply_to')) {
         $mail->AddReplyTo(\Openclerk\Config::get('phpmailer_reply_to'));
     }
     if (\Openclerk\Config::get('phpmailer_bcc', false)) {
         $mail->AddBCC(\Openclerk\Config::get('phpmailer_bcc'));
     }
     $mail->Subject = $subject;
     if ($html_message) {
         $mail->Body = $html_message;
         $mail->AltBody = $message;
         $mail->IsHTML(true);
     } else {
         $mail->Body = $message;
     }
     if (!$mail->Send()) {
         throw new MailerException("Message could not be sent: " . $mail->ErrorInfo);
     }
     return $mail->GetLastMessageID();
 }