diff --git a/common/framework/drivers/mail/dummy.php b/common/framework/drivers/mail/dummy.php new file mode 100644 index 000000000..2a4dc49e7 --- /dev/null +++ b/common/framework/drivers/mail/dummy.php @@ -0,0 +1,34 @@ +message->getTo()) + { + foreach($to as $address => $name) + { + $recipients[] = $address; + } + } + if ($cc = $message->message->getCc()) + { + foreach($cc as $address => $name) + { + $recipients[] = $address; + } + } + if ($bcc = $message->message->getBcc()) + { + foreach($bcc as $address => $name) + { + $recipients[] = $address; + } + } + + // Prepare data and options for Requests. + $boundary = str_repeat('-', 24) . substr(md5(mt_rand()), 0, 16); + $headers = array( + 'Content-Type' => 'multipart/form-data; boundary=' . $boundary, + ); + $data = implode("\r\n", array( + '--' . $boundary, + 'Content-Disposition: form-data; name="to"', + '', + implode(', ', $recipients), + '--' . $boundary, + 'Content-Disposition: attachment; name="message"; filename="message.eml"', + 'Content-Type: message/rfc822', + 'Content-Transfer-Encoding: binary', + '', + $message->message->toString(), + '--' . $boundary . '--', + '', + )); + $options = array( + 'auth' => array('api', $this->_config['api_token']), + 'timeout' => 5, + 'useragent' => 'PHP', + ); + + // Send the API request. + $url = self::$_url . '/' . $this->_config['api_domain'] . '/messages.mime'; + $request = \Requests::post($url, $headers, $data, $options); + $result = @json_decode($request->body); + + // Parse the result. + if (!$result) + { + $message->errors[] = 'Mailgun: Connection error: ' . $request->body; + return false; + } + elseif (!$result->id) + { + $message->errors[] = 'Mailgun: ' . $result->message; + return false; + } + else + { + return true; + } + } +} diff --git a/common/framework/drivers/mail/mandrill.php b/common/framework/drivers/mail/mandrill.php new file mode 100644 index 000000000..e360a3ecd --- /dev/null +++ b/common/framework/drivers/mail/mandrill.php @@ -0,0 +1,32 @@ +errors[] = $error; + $message->errors[] = 'Failed to send to ' . $error; } return (bool)$result; }