*
* @param string name of recipient
* @param string email of recipient
* @param string email subject
* @param string email body
* @param string sender name
* @param string sender e-mail
* @param array extra headers in form $headers = array($name => $value) to allow parsing
* @param array data file (path and filename)
* @param array data to attach a file (optional)
* @param bool True for attaching a embedded file inside content html (optional)
* @return returns true if mail was sent
* @see class.phpmailer.php
*/
function api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '', $extra_headers = array(), $data_file = array(), $embedded_image = false)
{
global $platform_email;
$mail = new PHPMailer();
$mail->Mailer = $platform_email['SMTP_MAILER'];
$mail->Host = $platform_email['SMTP_HOST'];
$mail->Port = $platform_email['SMTP_PORT'];
$mail->CharSet = $platform_email['SMTP_CHARSET'];
$mail->WordWrap = 200; // Stay far below SMTP protocol 980 chars limit.
if ($platform_email['SMTP_AUTH']) {
$mail->SMTPAuth = 1;
$mail->Username = $platform_email['SMTP_USER'];
$mail->Password = $platform_email['SMTP_PASS'];
}
$mail->Priority = 3; // 5 = low, 1 = high
$mail->AddCustomHeader('Errors-To: '.$platform_email['SMTP_FROM_EMAIL']);
$mail->SMTPKeepAlive = true;
if (($sender_email != '') && ($sender_name != '')) {
$mail->AddReplyTo($sender_email, $sender_name);
}
if (isset($extra_headers['reply_to'])) {
$mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']);
}
// Attachments
// $mail->AddAttachment($path);
// $mail->AddAttachment($path, $filename);
if ($sender_email != '') {
$mail->From = $sender_email;
$mail->Sender = $sender_email;
//$mail->ConfirmReadingTo = $sender_email; // Disposition-Notification
} else {
$mail->From = $platform_email['SMTP_FROM_EMAIL'];
$mail->Sender = $platform_email['SMTP_FROM_EMAIL'];
//$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; // Disposition-Notification
}
if ($sender_name != '') {
$mail->FromName = $sender_name;
} else {
$mail->FromName = $platform_email['SMTP_FROM_NAME'];
}
$mail->Subject = $subject;
$mail->AltBody = strip_tags(str_replace('
',"\n", api_html_entity_decode($message)));
// Send embedded image.
if ($embedded_image) {
// Get all images html inside content.
preg_match_all("/]*)[\"\']?[^>]*>/i", $message, $m);
// Prepare new tag images.
$new_images_html = array();
$i = 1;
if (!empty($m[1])) {
foreach ($m[1] as $image_path) {
$real_path = realpath($image_path);
$filename = basename($image_path);
$image_cid = $filename.'_'.$i;
$encoding = 'base64';
$image_type = mime_content_type($real_path);
$mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type);
$new_images_html[] = '';
$i++;
}
}
// Replace origin image for new embedded image html.
$x = 0;
if (!empty($m[0])) {
foreach ($m[0] as $orig_img) {
$message = str_replace($orig_img, $new_images_html[$x], $message);
$x++;
}
}
}
$message = str_replace(array("\n\r", "\n", "\r"), '
', $message);
$mail->Body = '