* @version $Id$
* @access public
* @license http://opensource.org/licenses/gpl-3.0.html
* @see /newsletter/send.php Direct file called by the application
*/
if(defined('MAIL_LIBRARY') && MAIL_LIBRARY == 'swiftMailer') $mailerLibrary = 'swiftMailer';
else $mailerLibrary = 'mailer'; // alternative 'swiftMailer'
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Address;
/**
* absolute_url
* http://www.howtoforge.com/forums/showthread.php?t=4
* @param string $txt
* @param string $base_url
* @return string $txt
*/
function absolute_url($txt, $base_url) {
$needles = array('href="', 'src="', 'background="');
$new_txt = '';
if(substr($base_url,-1) != '/') $base_url .= '/';
$new_base_url = $base_url;
$base_url_parts = parse_url($base_url);
foreach($needles as $needle){
while($pos = strpos($txt, $needle)){
$pos += strlen($needle);
if(substr($txt,$pos,7) != 'http://' && substr($txt,$pos,8) != 'https://' && substr($txt,$pos,6) != 'ftp://' && substr($txt,$pos,7) != 'mailto:'){
if(substr($txt,$pos,1) == '/') $new_base_url = $base_url_parts['scheme'].'://'.$base_url_parts['host'];
$new_txt .= substr($txt,0,$pos).$new_base_url;
} else {
$new_txt .= substr($txt,0,$pos);
}
$txt = substr($txt, $pos);
}
$txt = $new_txt . $txt;
$new_txt = '';
}
return $txt;
}
// https://symfony.com/doc/current/mailer.html
$mailer_dsn = 'native://default'; // default configuration
// We create the Transport
if (defined('MAIL_MAILER')) {
// sendmail
if (MAIL_MAILER == 'sendmail') {
$mailer_dsn = 'sendmail://default';
$transport = new Swift_SendmailTransport(MAIL_SENDMAIL); // alternative 'swiftMailer'
}
// smtp
if (MAIL_MAILER == 'smtp') {
if (defined('MAIL_SMTP_AUTH') && MAIL_SMTP_AUTH == 1) {
if (defined('MAIL_SMTP_ENCRYPTION')) {
$mailer_dsn = 'smtp://' . MAIL_SMTP_USER . ':' . MAIL_SMTP_PASS . '@' . MAIL_HOST . ':' . MAIL_PORT;
$transport = (new Swift_SmtpTransport(MAIL_HOST, MAIL_PORT, MAIL_SMTP_ENCRYPTION))->setUsername(MAIL_SMTP_USER)->setPassword(MAIL_SMTP_PASS); // alternative 'swiftMailer'
} else {
$mailer_dsn = 'smtp://' . MAIL_SMTP_USER . ':' . MAIL_SMTP_PASS . '@' . MAIL_HOST . '?verify_peer=0:' . MAIL_PORT;
$transport = (new Swift_SmtpTransport(MAIL_HOST, MAIL_PORT))->setUsername(MAIL_SMTP_USER)->setPassword(MAIL_SMTP_PASS); // alternative 'swiftMailer'
}
} else {
$mailer_dsn = 'smtp://' . MAIL_HOST . ':' . MAIL_PORT;
$transport = (new Swift_SmtpTransport(MAIL_HOST, MAIL_PORT)); // alternative 'swiftMailer'
}
}
}
// we define mailer transport settings
$transportMailer = Transport::fromDsn($mailer_dsn);
$mailer = new Mailer($transportMailer);
// Create the Swift_Mailer using the Transport if set as mailer library
if( $mailerLibrary == 'swiftMailer') $mailer = new Swift_Mailer($transport);
/**
* Ability to set options through plugins
* examples taken from :
* http://swiftmailer.org/docs/plugins.html
* Duplicate original file and locate it into public themes
* Finally uncomment instructions and set them correcty
*/
// // Use AntiFlood to re-connect after 100 emails
// $mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100));
// // And specify a time in seconds to pause for (30 secs)
// $mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100, 30));
// // Rate limit to 100 emails per-minute
// $mailer->registerPlugin(new Swift_Plugins_ThrottlerPlugin(
// 100, Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE
// ));
// // Rate limit to 10MB per-minute
// $mailer->registerPlugin(new Swift_Plugins_ThrottlerPlugin(
// 1024 * 1024 * 10, Swift_Plugins_ThrottlerPlugin::BYTES_PER_MINUTE
// ));
/**
echo "destinataire : ".$email_recipient."
";
echo "sujet : ".$email_subject."
";
echo "body : ".$email_html_body."
";
echo "methode : ".$email_method."
";
echo "host : ".$mail->Host."
";
echo "port : ".$mail->Port."
";
*/
for($i = 0;$i < count($newsletters); $i++) {
$newsletter_id = $newsletters[$i]['newsletter_id'];
$email_subject = formatText($newsletters[$i]['newsletter_title'], '2HTML');
$newsletter_body_html = formatText($newsletters[$i]['newsletter_body'], '2HTML');
// get content with SIMPLEHTMLDOM
$dom = str_get_html($template_html);
// we do replace the content from template with content stored id db inside