linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file template_newsletter.php

Documentation is available at template_newsletter.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage mail
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11.  
  12. /**
  13.  * absolute_url
  14.  * http://www.howtoforge.com/forums/showthread.php?t=4
  15.  * @param $txt 
  16.  * @param $base_url 
  17.  */
  18. function absolute_url($txt, $base_url) {
  19.   $needles = array('href="', 'src="', 'background="');
  20.   $new_txt = '';
  21.   if(substr($base_url,-1) != '/') $base_url .= '/';
  22.   $new_base_url = $base_url;
  23.   $base_url_parts = parse_url($base_url);
  24.  
  25.   foreach($needles as $needle){
  26.     while($pos = strpos($txt, $needle)){
  27.       $pos += strlen($needle);
  28.       if(substr($txt,$pos,7) != 'http://' && substr($txt,$pos,8) != 'https://' && substr($txt,$pos,6) != 'ftp://' && substr($txt,$pos,9) != 'mailto://'){
  29.         if(substr($txt,$pos,1) == '/') $new_base_url = $base_url_parts['scheme'].'://'.$base_url_parts['host'];
  30.         $new_txt .= substr($txt,0,$pos).$new_base_url;
  31.       } else {
  32.         $new_txt .= substr($txt,0,$pos);
  33.       }
  34.       $txt = substr($txt,$pos);
  35.     }
  36.     $txt = $new_txt.$txt;
  37.     $new_txt = '';
  38.   }
  39.   return $txt;
  40. }
  41.  
  42. include_once("../class/system/class.phpmailer.php");
  43.  
  44. $mail = new phpmailer();
  45.  
  46. if(defined('MAIL_PORT')) $mail->Port = MAIL_PORT;
  47.  
  48. if (defined('MAIL_MAILER')) {
  49.   $mail->Mailer = MAIL_MAILER;
  50.   if(MAIL_MAILER=='sendmail') {
  51.     if(defined('MAIL_SENDMAIL')) $mail->Sendmail = MAIL_SENDMAIL;
  52.   }
  53.   if(MAIL_MAILER=='smtp') {
  54.     if(defined('MAIL_HOST')) $mail->Host = MAIL_HOST;
  55.     
  56.   }
  57. }
  58.  
  59. if (defined('MAIL_SMTP_AUTH') && MAIL_SMTP_AUTH == true) {
  60.   $mail->SMTPAuth = MAIL_SMTP_AUTH;
  61.   if (defined('MAIL_SMTP_USER')) $mail->Username = MAIL_SMTP_USER;
  62.   if (defined('MAIL_SMTP_PASS')) $mail->Password = MAIL_SMTP_PASS;
  63. }
  64.  
  65. /**
  66.  echo "destinataire : ".$email_dest."<br />";
  67.  echo "sujet : ".$email_subject."<br />";
  68.  echo "body : ".$email_html_body."<br />";
  69.  echo "methode : ".$email_method."<br />";
  70.  echo "host : ".$mail->Host."<br />";
  71.  echo "port : ".$mail->Port."<br />";
  72.  */
  73.  
  74. for($i = 0;$i < count($newsletters); $i++) {
  75.   $newsletter_id = $newsletters[$i]['newsletter_id'];
  76.   $email_subject = formatText($newsletters[$i]['newsletter_title'], '2HTML');
  77.  
  78.   $newsletter_body_html = formatText($newsletters[$i]['newsletter_body'], '2HTML');
  79.   preg_replace("/(<\s*(a|img)\s+[^>]*(href|src)\s*=\s*[\"'])(?!http)([^\"'>]+)[\"'>]/", "$1".CURRENT_APP_URL."$4", $newsletter_body_html);
  80.   $email_html_body=str_replace('##TITLE##', $email_subject, $template_html);
  81.   $email_html_body=str_replace('##CHARSET##', CHARSET, $email_html_body);
  82.   $email_html_body=str_replace('##CONTENTS##', $newsletter_body_html, $email_html_body);
  83.   $email_html_body=str_replace('##SITENAME##', SITE_NAME, $email_html_body);
  84.   $email_html_body=str_replace('##CSSPATH##', SITE_ROOT_URL. THEME_DIRECTORY.'/public/'.THEME_PUBLIC.'/css/', $email_html_body);
  85.   $email_html_body=str_replace('##SITEURL##', SITE_ROOT_URL, $email_html_body);
  86.   $email_html_body=str_replace('##SITEMAIL##', SITE_MAIL, $email_html_body);
  87.   $email_html_body=absolute_url($email_html_body, SITE_ROOT_URL);
  88.  
  89.   $newsletter_body_txt = formatText($newsletters[$i]['newsletter_body']);
  90.   $email_text_body=str_replace('##TITLE##', strip_tags(formatText($email_subject)), $template_txt);
  91.   $email_text_body=str_replace('##CONTENTS##', strip_tags(formatText($newsletter_body_txt)), $email_text_body);
  92.   $email_text_body=str_replace('##SITENAME##', SITE_NAME, $email_text_body);
  93.   $email_text_body=str_replace('##SITEURL##', SITE_ROOT_URL, $email_text_body);
  94.   $email_text_body=str_replace('##SITEMAIL##', SITE_MAIL, $email_text_body);
  95.   $email_text_body=absolute_url($email_text_body, SITE_ROOT_URL);
  96.   
  97.  
  98.   $mail->CharSet = CHARSET;
  99.   $mail->From = MAIL_FROM;
  100.   $mail->FromName = MAIL_FROMNAME;
  101.   $mail->Subject = $email_subject;
  102.   $mail->WordWrap = 75;
  103.   $mail->Body = $email_html_body;
  104.   $mail->AltBody = str_replace('&amp;', '&', $email_text_body);
  105.   $mail->AddReplyTo(MAIL_REPLY, MAIL_REPLYNAME);
  106.  
  107.   for($k = 0; $k < count($emails_batch); $k++) {
  108.     $email_id = $emails_batch[$k]['emailcol_id'];
  109.     $email_dest = $emails_batch[$k]['emailcol_email'];
  110.  
  111.     $mail->AddAddress($email_dest);
  112.  
  113.     $r = $mail->Send();
  114.     logfile(LOG_MAILING, array($mail->Subject, $newsletter_id, $email_dest, $mail->ErrorInfo));
  115.  
  116.     $mail->ClearAddresses();
  117.     $mail->ClearAttachments();
  118.   }
  119.   
  120.   if(!isset($doNotPublish)) $newsletter_object->SetNewsletterPublished($newsletter_id, $sql_object);
  121. }
  122.  
  123. ?>

Documentation generated on Thu, 03 May 2012 15:07:48 +0200 by phpDocumentor 1.4.1