I have wrote some SendMail.class.php class which will send mails. But it is working - it send only to the last one address.
It is class code: (class is not according to API standard)
class SendMail {
public $mails = array();
public $to;
public $subject;
public $message;
public $sender;
public $headers;
public $content;
public $notSent = array();
public $sent;
public function __construct($file)
{
$this->mails = file($file);
}
public function setData($subject = '', $message = '', $sender = '')
{
$this->subject = $subject;
$this->message = $message;
$this->sender = $sender;
}
public function sendMails()
{
$this->headers = 'From: ' . $this->sender . "\r\n" .
'Reply-To: ' . $this->sender . "\r\n" .
'Content-type: text/html; charset=utf-8';
for($i = 0; $i <= count($this->mails); $i++)
{
$try = mail($this->mails[$i], $this->subject, $this->message, $this->headers);
if (!$try) {
$this->notSent[] = $this->mails[$i];
} else {
$this->sent[] = $this->mails[$i];
}
}
}
public function createRaport($dir)
{
$date = date("d-m-y");
$file = date("d-m-Y-i-s") . '.txt';
$this->content = 'Raport z dnia ' . $date . "\r\n" .
'* Próbowano wysłać e-maile do ' . count($this->mails) . ' adresów' . "\r\n" .
'* Wysłano do ' . (count($this->mails) - count($this->notSent) + 1) . ' użytkowników' . "\r\n" .
'* Nadawca : ' . $this->sender . "\r\n" .
'* Tytuł wiadomości : ' . $this->subject . "\r\n" .
'* Treść wiadomości była następująca : ' . "\r\n" .
'<div id="try_message">' . $this->message . '</div>' . "\r\n" .
'* Nie wysłano do: ' . "\r\n";
foreach($this->notSent as $row)
{
if ($row != '') {
$this->content .= '* ' . $row;
}
}
$this->content .= "\r\n\r\n";
$this->content .= '* Wysłano do: ' . "\r\n";
foreach($this->sent as $row)
{
if (count($this->sent) == 0) {
$this->content .= '* brak wysłanych maili';
} else {
$this->content .= '* ' . $row;
}
}
$this->content .= 'Koniec raportu!' . "\r\n" .
'Raport stworzony za pomocą silnika stworzonego przez Adriana Wierciocha!';
$handle = fopen($dir . $file, "a");
$try = fwrite($handle, $this->content);
if (!$try) {
return false;
} else {
return $file;
}
}
public function showNotSent()
{
return $this->notSent;
}
public function showRaport()
{
return nl2br($this->content);
}
}
and script running it:
session_start();
require_once('paths_set.php');
set_time_limit(240);
if(!isset($_GET['step'])) {
$step = 'index';
} else {
$step = $_GET['step'];
}
switch ($step)
{
case 'write' :
$action = 'send_write';
require_once(VIEW_FILE);
break;
case 'try' :
require_once(LIB_DIR . 'SendMail.class.php');
$base = APPLICATION_PATH . 'mailbase/' . $_GET['base'] . '.base';
$model = new SendMail($base);
$model->setData($_POST['subject'], $_POST['message'], $_POST['sender']);
$model->sendMails();
$errors = $model->showNotSent();
$raport = $model->createRaport( RAPORT_DIR );
$content = $model->showRaport();
$action = 'send_try';
require_once(VIEW_FILE);
break;
case 'show' :
$file = APPLICATION_PATH . 'mailbase/' . $_GET['base'] . '.base';
$mails = file($file);
$action = 'send_show';
require_once(VIEW_FILE);
break;
default:
$action = 'send';
require_once(VIEW_FILE);
break;
}
I need your help so much because I have to sell it system rapidly :cool:


Sign In
Create Account


Back to top









