diff options
-rw-r--r-- | utils/mail.php | 25 | ||||
-rw-r--r-- | utils/modules/newsletter.php | 57 |
2 files changed, 48 insertions, 34 deletions
diff --git a/utils/mail.php b/utils/mail.php new file mode 100644 index 0000000..866bad4 --- /dev/null +++ b/utils/mail.php @@ -0,0 +1,25 @@ +<?php /* -*- mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +class Email { + public $timestamp; + public $email; + + public function Email($email, $timestamp) + { + $this->email = $email; + $this->timestamp = $timestamp; + } + + public function send($subject, $message, + $sender, $replyto) + { + $headers = "From: " . $sender . "\r\n"; + $headers .= "Reply-To: " . $replyto . "\r\n"; + $headers .= "Content-Type: text/plain; charset=iso-8859-1\r\n"; + $headers .= "X-Mailer: PHP/" . phpversion(); + + return mail($this->email, $subject, $message, $headers); + } +} + +?>
\ No newline at end of file diff --git a/utils/modules/newsletter.php b/utils/modules/newsletter.php index 5a0cade..ef172e0 100644 --- a/utils/modules/newsletter.php +++ b/utils/modules/newsletter.php @@ -1,30 +1,8 @@ <?php /* -*- mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -class Email { - public $timestamp; - public $email; +global $UTIL_DIR; - public function Email($email, $timestamp) - { - $this->email = $email; - $this->timestamp = $timestamp; - } - - public function send($subject, $message, - $subject_prefix, $sender, $replyto, $footer, $unsubscribe_url) - { - $message .= "\n\n".$footer; - $message .= "\n\nTo stop receiving this newsletter, click the following link: ".$unsubscribe_url."&action=unsubscribe&email=". $this->email . "\n"; - $headers = "From: " . $sender . "\r\n"; - $headers .= "Reply-To: " . $replyto . "\r\n"; - $headers .= "Content-Type: text/plain; charset=iso-8859-1\r\n"; - $headers .= "X-Mailer: PHP/" . phpversion(); - $subject = "[".$subject_prefix."] " . $subject; - - $ret = mail($this->email, $subject, $message, $headers); - if(!$ret) echo "Fail(".$this->email.")"; - } -} +include_once($UTIL_DIR . "/mail.php"); class Mailinglist { private $file; @@ -125,8 +103,26 @@ class Mailinglist { return $str; } + public function postSingle($email, $subject, $message) + { + $subject = "[".$this->subj_prefix."] " . $subject; + + $message .= "\n\n".$this->footer; + $message .= "\n\nTo stop receiving this newsletter, click the following link: ". + $this->unsubscribe_url."&action=unsubscribe&email=". $email->email . "\n"; + + $email->send($subject, $message, $this->sender, $this->replyto); + } + public function post($subject, $message) { + $subject = "[".$this->subject_prefix."] " . $subject; + + $message .= "\n\n".$this->footer; + $message .= "\n\nTo stop receiving this newsletter, click the following link: ". + $this->unsubscribe_url."&action=unsubscribe&email=". $this->email . "\n"; + + $sz = sizeof($this->mailinglist); echo "<div style=\"text-align: center; padding-top: 120px; padding-bottom: 100px; position: absolute; top: 25%; left: 0px; width: 99.4%; height: 150px; border: solid #0000ff 3px; background: #fff; color: #000;\">Sending ". $sz ." mails <br/>\n<"; @@ -138,10 +134,8 @@ class Mailinglist { $steps = floor($sz / 10) + 1; foreach($this->mailinglist as $email) { - $email->send($subject, $message, - $this->subj_prefix, $this->sender, - $this->replyto, $this->footer, - $this->unsubscribe_url); + + $this->postSingle($email, $ubject, $message); $pct = $num / $sz * 100; if($pct >= $lvl) { @@ -190,12 +184,7 @@ class Newsletter { case "preview": $testmail = new Email($vars["testaddr"], 0); echo "<div class=\"preview\">\n"; - echo $testmail->send($vars["subject"], $vars["content"], - $this->mailinglist->subj_prefix, - $this->mailinglist->sender, - $this->mailinglist->replyto, - $this->mailinglist->footer, - $this->mailinglist->unsubscribe_url); + $this->mailinglist->postSingle($testmail, $vars["subject"], $vars["content"]); echo "A test mail has been sent to ".$vars["testaddr"]."</div>\n"; echo "<p>Looking ok?</p>"; $form = new Form("send"); |