* @version $Id$ * @access public * @license http://opensource.org/licenses/gpl-3.0.html */ /** * @param array $emailContainer * @return boolean True if sent, else false */ function send_email($emailContainer) { require_once '../lib/vendor/swift/lib/swift_required.php'; // We create the Transport if (defined ( 'MAIL_MAILER' )) { // by default $transport = Swift_MailTransport::newInstance (); // sendmail if (MAIL_MAILER == 'sendmail') { $transport = Swift_SendmailTransport::newInstance ( MAIL_SENDMAIL ); } // smtp if (MAIL_MAILER == 'smtp') { if (defined ( 'MAIL_SMTP_AUTH' ) && MAIL_SMTP_AUTH == 1) { if (defined ( 'MAIL_SMTP_ENCRYPTION')) { $transport = Swift_SmtpTransport::newInstance ( MAIL_HOST, MAIL_PORT, MAIL_SMTP_ENCRYPTION)->setUsername ( MAIL_SMTP_USER )->setPassword ( MAIL_SMTP_PASS ); } else { $transport = Swift_SmtpTransport::newInstance ( MAIL_HOST, MAIL_PORT)->setUsername ( MAIL_SMTP_USER )->setPassword ( MAIL_SMTP_PASS ); } } else { $transport = Swift_SmtpTransport::newInstance ( MAIL_HOST, MAIL_PORT ); } } } $html = new simple_html_dom(); $html->load($emailContainer['html_body']); // Find all images foreach($html->find('img') as $el) { if(Stringy\Stringy::create($el->src, CHARSET)->startsWith('http')) { // list($width, $height) = getimagesize($el->src); // @todo tested but to long with remote images ..... $el->class = 'emailImage'; $el->height = null; // to make auto fit ... // if($width > 520) $el->width = '100%'; if(isset($el->width) && (int) $el->width > 520) $el->width = '100%'; else $el->width = null; } } $emailContainer['html_body'] = $html; // echo "destinataire : ".$emailContainer['recipient']."
"; // echo "sujet : ".$emailContainer['subject']."
"; // echo "body : ".$emailContainer['html_body']."
"; // echo "body (txt) : ".$emailContainer['txt_body']."
"; // Create the Mailer using the Transport $mailer = Swift_Mailer::newInstance ( $transport ); isset ( $emailContainer ['from'] ) ? $from = $emailContainer ['from'] : $from = MAIL_FROM; isset ( $emailContainer ['from_name'] ) ? $fromname = $emailContainer ['from_name'] : $fromname = MAIL_FROMNAME; // $replyto must be an array() isset ( $emailContainer ['reply_to'] ) ? $replyto = $emailContainer ['reply_to'] : $replyto = array( MAIL_REPLY => MAIL_REPLYNAME ); $emailContainer ['txt_body'] = str_replace ( '&', '&', $emailContainer ['txt_body'] ); // if only one email is given we put it an array if (is_string ( $emailContainer ['recipient'] )) { $tmp = $emailContainer ['recipient']; $emailContainer ['recipient'] = array (); array_push ( $emailContainer ['recipient'], $tmp ); } // Create a message $message = Swift_Message::newInstance ( $emailContainer ['subject'] )->setFrom ( array ( $from => $fromname ) )->setBody ( $emailContainer ['html_body'], 'text/html' )->addPart ( $emailContainer ['txt_body'], 'text/plain' )->setReplyTo ( $replyto ); if (is_array ( $emailContainer ['recipient'] )) { for($i = 0; $i < count ( $emailContainer ['recipient'] ); $i ++) { $message->setTo ( $emailContainer ['recipient'] [$i] ); $r = $mailer->Send ( $message, $failures ); if (! $r) { $logmsg = 'not sent'; } else { $logmsg = 'sent'; } logfile ( LOG_MAILER, array ( $emailContainer ['subject'], $emailContainer ['recipient'] [$i], $logmsg ) ); if (! $r && MOD_DEBUG == 1) { _debug ( 'Mail has not been sent. "' . $emailContainer ['recipient'] [$i] . ' / ' . $emailContainer ['subject'] . '" : ' . $logmsg ); } } } // we clear SimpleHTMLDom to prevent memory leaks $html->clear(); unset($html); if (! $r) return false; else return true; } ?>