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_USE_SSL') && MAIL_USE_SSL== true) {
  47.   $mail->Host = MAIL_HOST_SSL;
  48.   $mail->Port = MAIL_PORT_SSL;
  49. }
  50. if (defined('MAIL_MAILER')) {
  51.   $mail->Mailer = MAIL_MAILER;
  52.   if(MAIL_MAILER=='sendmail') {
  53.     if(defined('MAIL_SENDMAIL')) $mail->Sendmail = MAIL_SENDMAIL;
  54.   }
  55.   if(MAIL_MAILER=='smtp') {
  56.     if(defined('MAIL_HOST')) $mail->Host = MAIL_HOST;
  57.   }
  58. }
  59.  
  60. if (defined('MAIL_SMTP_AUTH') && MAIL_SMTP_AUTH == true) {
  61.   $mail->SMTPAuth = MAIL_SMTP_AUTH;
  62.   if (defined('MAIL_SMTP_USER')) $mail->Username = MAIL_SMTP_USER;
  63.   if (defined('MAIL_SMTP_PASS')) $mail->Password = MAIL_SMTP_PASS;
  64. }
  65.  
  66. /**
  67.  echo "destinataire : ".$email_dest."<br />";
  68.  echo "sujet : ".$email_subject."<br />";
  69.  echo "body : ".$email_html_body."<br />";
  70.  echo "methode : ".$email_method."<br />";
  71.  echo "host : ".$mail->Host."<br />";
  72.  echo "port : ".$mail->Port."<br />";
  73.  */
  74.  
  75. for($i = 0;$i < count($newsletters); $i++) {
  76.   $newsletter_id = $newsletters[$i]['newsletter_id'];
  77.   $email_subject = formatText($newsletters[$i]['newsletter_title'], '2HTML');
  78.  
  79.   $newsletter_body_html = formatText($newsletters[$i]['newsletter_body'], '2HTML');
  80.   preg_replace("(<\s*(a|img)\s+[^>]*(href|src)\s*=\s*[\"'])(?!http)([^\"'>]+)[\"'>]", "$1".CURRENT_APP_URL."$4", $newsletter_body_html);
  81.   $email_html_body=str_replace('##TITLE##', $email_subject, $template_html);
  82.   $email_html_body=str_replace('##CHARSET##', CHARSET, $email_html_body);
  83.   $email_html_body=str_replace('##CONTENTS##', $newsletter_body_html, $email_html_body);
  84.   $email_html_body=str_replace('##SITENAME##', SITE_NAME, $email_html_body);
  85.   $email_html_body=str_replace('##CSSPATH##', SITE_ROOT_URL. THEME_DIRECTORY.'/public/'.THEME_PUBLIC.'/css/', $email_html_body);
  86.   $email_html_body=str_replace('##SITEURL##', SITE_ROOT_URL, $email_html_body);
  87.   $email_html_body=str_replace('##SITEMAIL##', SITE_MAIL, $email_html_body);
  88.   $email_html_body=absolute_url($email_html_body, SITE_ROOT_URL);
  89.  
  90.   $newsletter_body_txt = formatText($newsletters[$i]['newsletter_body']);
  91.   $email_text_body=str_replace('##TITLE##', strip_tags(formatText($email_subject)), $template_txt);
  92.   $email_text_body=str_replace('##CONTENTS##', strip_tags(formatText($newsletter_body_txt)), $email_text_body);
  93.   $email_text_body=str_replace('##SITENAME##', SITE_NAME, $email_text_body);
  94.   $email_text_body=str_replace('##SITEURL##', SITE_ROOT_URL, $email_text_body);
  95.   $email_text_body=str_replace('##SITEMAIL##', SITE_MAIL, $email_text_body);
  96.   $email_text_body=absolute_url($email_text_body, SITE_ROOT_URL);
  97.   
  98.  
  99.   $mail->CharSet = CHARSET;
  100.   $mail->From = MAIL_FROM;
  101.   $mail->FromName = MAIL_FROMNAME;
  102.   $mail->Subject = $email_subject;
  103.   $mail->WordWrap = 75;
  104.   $mail->Body = $email_html_body;
  105.   $mail->AltBody = str_replace('&amp;', '&', $email_text_body);
  106.   $mail->AddReplyTo(MAIL_REPLY, MAIL_REPLYNAME);
  107.  
  108.   for($k = 0; $k < count($emails_batch); $k++) {
  109.     $email_id = $emails_batch[$k]['emailcol_id'];
  110.     $email_dest = $emails_batch[$k]['emailcol_email'];
  111.  
  112.     $mail->AddAddress($email_dest);
  113.  
  114.     $r = $mail->Send();
  115.     logfile(LOG_MAILING, array($mail->Subject, $newsletter_id, $email_dest, $mail->ErrorInfo));
  116.  
  117.     $mail->ClearAddresses();
  118.     $mail->ClearAttachments();
  119.   }
  120.   $newsletter_object->SetNewsletterPublished($newsletter_id, $sql_object);
  121. }
  122.  
  123. ?>

Documentation generated on Fri, 01 Apr 2011 09:35:06 +0200 by phpDocumentor 1.4.1