45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Implements MailSystemInterface
|
|
* Taken from http://www.ardoubleyou.com/blog/how-programmatically-send-e-mail-using-html-and-text-content-type-drupal-7
|
|
*/
|
|
class BookingMailSystem implements MailSystemInterface {
|
|
/**
|
|
* Concatenate and wrap the e-mail body for plain-text mails
|
|
* @param $message
|
|
* A message array, as described in hook_mail_alter().
|
|
*
|
|
* @return
|
|
* The formatted $message
|
|
*/
|
|
public function format(array $message) {
|
|
$message['body'] = implode("\n\n", $message['body']);
|
|
//watchdog('booking_debug', "<pre>BookingMailSystem format:\n@info</pre>", array('@info' => print_r( $message, true)));
|
|
return $message;
|
|
}
|
|
|
|
/**
|
|
* Send an e-mail message, using Drupal variables and default settings.
|
|
* @see drupal_mail*()
|
|
* @param $message
|
|
* A message array, as described in hook_mail_alter()
|
|
* @return
|
|
* TRUE if the mail was successfully accepted, otherwise FALSE
|
|
*/
|
|
public function mail(array $message) {
|
|
$mimeheaders = array();
|
|
foreach($message['headers'] as $name => $value) {
|
|
$mimeheaders[] = $name . ': ' . mime_header_encode($value);
|
|
}
|
|
$line_endings = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
|
|
$mail = mail(
|
|
$message['to'],
|
|
mime_header_encode($message['subject']),
|
|
preg_replace('@\r?\n@', $line_endings, $message['body']),
|
|
join("\n", $mimeheaders)
|
|
);
|
|
//watchdog('booking_debug', "<pre>BookingMailSystem mail:\n@info</pre>", array('@info' => print_r( $mail, true)));
|
|
return $mail;
|
|
}
|
|
} |