public function send() { $mail = new PHPMailer(); foreach ($this->to as $to) { $mail->AddAddress($to); } $mail->IsMail(); $mail->Subject = $this->subject; $mail->From = MAIL_REPLY_TO; $mail->FromName = $this->fromName ?: MAIL_FROM_NAME; $mail->Sender = MAIL_REPLY_TO; if ($this->replyTo) { $mail->AddReplyTo($this->replyTo); } $mail->Body = $this->body; if (substr(trim($this->body), 0, 1) == '<') { $mail->IsHTML(true); if (isset($this->plain_body)) { $mail->AltBody = html_entity_decode($this->plain_body); } } else { $mail->Body = html_entity_decode($this->body); $mail->IsHTML(false); } if (IS_PRODUCTION) { return $mail->Send(); } else { \jmvc::log(print_r($mail, true), 'mail'); } }
/** * Sends the e-mail. Prints debug output if debug mode is turned on * @return Mail_Postmark */ public function &send() { $this->preSendCheck(); if (!IS_PRODUCTION) { static $sent = false; if (!defined('TEST_EMAIL_ADDRESS') || $sent) { return; } $this->_toAddress = array(TEST_EMAIL_ADDRESS); $sent = true; } $data = $this->_prepareData(); $headers = array('Accept: application/json', 'Content-Type: application/json', 'X-Postmark-Server-Token: ' . POSTMARKAPP_API_KEY); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://api.postmarkapp.com/email'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $return = curl_exec($ch); if ($this->_debugMode == self::DEBUG_VERBOSE) { echo "JSON: " . json_encode($data) . "\nHeaders: \n\t" . implode("\n\t", $headers) . "\nReturn:\n{$return}"; } else { if ($this->_debugMode == self::DEBUG_RETURN) { return array('json' => json_encode($data), 'headers' => $headers, 'return' => $return); } } if (curl_error($ch) != '') { \jmvc::log(date('r') . "\nPostmark CURL error: " . curl_error($ch), 'postmark'); return $this; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (!self::_isTwoHundred($httpCode)) { $message = json_decode($return)->Message; \jmvc::log(date('r') . "\nPostmark Error {$httpCode}:" . $message, 'postmark'); } return $this; }