2011-02-19 13:33:42 +00:00
|
|
|
<?php
|
2011-09-18 11:34:17 +00:00
|
|
|
|
|
|
|
require_once('include/email.php');
|
|
|
|
|
2014-09-06 13:52:53 +00:00
|
|
|
class Emailer {
|
2011-02-19 13:33:42 +00:00
|
|
|
/**
|
|
|
|
* Send a multipart/alternative message with Text and HTML versions
|
|
|
|
*
|
|
|
|
* @param fromName name of the sender
|
|
|
|
* @param fromEmail email fo the sender
|
|
|
|
* @param replyTo replyTo address to direct responses
|
|
|
|
* @param toEmail destination email address
|
|
|
|
* @param messageSubject subject of the message
|
|
|
|
* @param htmlVersion html version of the message
|
|
|
|
* @param textVersion text only version of the message
|
2014-09-06 13:52:53 +00:00
|
|
|
* @param additionalMailHeader additions to the smtp mail header
|
2011-02-19 13:33:42 +00:00
|
|
|
*/
|
2014-09-06 13:52:53 +00:00
|
|
|
static public function send($params) {
|
|
|
|
|
|
|
|
$fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
|
|
|
|
$messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
|
2011-09-18 11:34:17 +00:00
|
|
|
|
2011-02-19 13:33:42 +00:00
|
|
|
// generate a mime boundary
|
|
|
|
$mimeBoundary =rand(0,9)."-"
|
|
|
|
.rand(10000000000,9999999999)."-"
|
|
|
|
.rand(10000000000,9999999999)."=:"
|
|
|
|
.rand(10000,99999);
|
|
|
|
|
|
|
|
// generate a multipart/alternative message header
|
|
|
|
$messageHeader =
|
2014-09-06 13:52:53 +00:00
|
|
|
$params['additionalMailHeader'] .
|
|
|
|
"From: $fromName <{$params['fromEmail']}>\n" .
|
|
|
|
"Reply-To: $fromName <{$params['replyTo']}>\n" .
|
2011-02-19 13:33:42 +00:00
|
|
|
"MIME-Version: 1.0\n" .
|
|
|
|
"Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
|
|
|
|
|
|
|
|
// assemble the final multipart message body with the text and html types included
|
2014-09-06 13:52:53 +00:00
|
|
|
$textBody = chunk_split(base64_encode($params['textVersion']));
|
|
|
|
$htmlBody = chunk_split(base64_encode($params['htmlVersion']));
|
2011-02-19 13:33:42 +00:00
|
|
|
$multipartMessageBody =
|
|
|
|
"--" . $mimeBoundary . "\n" . // plain text section
|
|
|
|
"Content-Type: text/plain; charset=UTF-8\n" .
|
|
|
|
"Content-Transfer-Encoding: base64\n\n" .
|
|
|
|
$textBody . "\n" .
|
|
|
|
"--" . $mimeBoundary . "\n" . // text/html section
|
|
|
|
"Content-Type: text/html; charset=UTF-8\n" .
|
|
|
|
"Content-Transfer-Encoding: base64\n\n" .
|
|
|
|
$htmlBody . "\n" .
|
|
|
|
"--" . $mimeBoundary . "--\n"; // message ending
|
|
|
|
|
|
|
|
// send the message
|
|
|
|
$res = mail(
|
2014-09-06 13:52:53 +00:00
|
|
|
$params['toEmail'], // send to address
|
2011-02-19 13:33:42 +00:00
|
|
|
$messageSubject, // subject
|
|
|
|
$multipartMessageBody, // message body
|
|
|
|
$messageHeader // message headers
|
|
|
|
);
|
2014-09-06 13:52:53 +00:00
|
|
|
logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
|
2014-09-07 09:20:06 +00:00
|
|
|
logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);
|
2011-02-19 13:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-06 13:52:53 +00:00
|
|
|
?>
|