<?php
class Mailer {
protected $_mails = array();
public $file_path;
public $error_message;
public $errors = array();
public $subject;
public $p_mails;
//constructor
function __construct($file)
{
$this->file_path = $file;
if (file_exists($this->file_path)) {
$this->_mails = file($file);
} else {
die();
}
}
//setter
public function __set($name, $value)
{
$this->$name = $value;
}
//function returns all e-mails
public function showAllMails()
{
if (count($this->_mails) = 0) {
return false;
} else {
return $this->_mails;
}
}
//function which add content of message
public function insertMessage($message)
{
$message = htmlspecialchars($message);
$this->message = $message;
}
//function which add subject
public function insertSubject($subject);
{
$sub = htmlsepcialchars($subject);
$this->subject = $sub;
}
//function prepares mails to send
public function prepareMails($array)
{
$this->p_mails = $array;
}
public function sendMails()
{
for($i=0;$i<=count($this->_mails);$i++)
{
if (count($this->p_mails) == 0 || $this->subject == '' || $this->message == '')
{
return false;
} else {
$try = mail($this->p_mails[$i], $this->subject, $this->message);
if(!$try)
{
$this->errors['mail'][] = $this->mails[$i];
}
}
}
}
//this function returns mails, which does not send
public function showDoNotSend()
{
return $this->errors['mails'];
}
}
?>
I need your help because i do not know if function sends mails is capacity, because this method will send about 2000 mails in once. I`m programming just 1,5 years and I have never learned write perfect application.
Second, I write simple configure file which is common to all files in application, precisely to php files which are executing while some user is browsing my page, something like controller in php`s framework as look as : localhost/send.php localhost/add_mails.php. My problem is in speed of executing this file. It look like this:
<?php
/*
************************************
* system mailowy stworzony przez: *
* AdrianWierciochPHP *
************************************
*
* Plik konfiguracyjny
*
*/
//check if configuration file exists
if (!file_exists('config.ini')) {
die('<p>Główny plik konfiguracyjny nie istnieje! Skontaktuj się z <a mailto="wiercioch.adrian1993@gmail.com">wiercioch.adrian1993@gmail.com</a>!</p>');
}
$config = parse_ini_file('config.ini');
//definiowanie stałych
define('SMARTY_DIR', $config['smarty.dir']);
define('TEMPLATE_DIR', $config['smarty.dir.template']);
define('COMPILE_DIR', $config['smarty.dir.compile']);
define('CONFIG_DIR', $config['smarty.dir.config']);
define('CACHE_DIR', $config['smarty.dir.cache']);
define('EMAIL_ADDRESS', $config['author.mail']);
define('FILE_SET_LANG', $config['file.set.language']); /* do not need */
define('FILE_STACK_MAILS', $config['file.stack.mails']);
define('EXT_T', $config['smarty.templates.extension']);
define('SMARTY_DISPLAY_INDEX', $config['smarty.display.index']);
define('SMARTY_DISPLAY_SEND', $config['smarty.display.send']);
define('SMARTY_DISPLAy_ERROR', $config['smarty.display.error']);
define('LANGUAGE', $config['language']);
define('LIBRARY', $config['library']);
define('MARK', $config['main.mark']);
//including SMARTY class
include_once(SMARTY_DIR . 'Smarty.class.php');
//configure language of application
require_once('lib/Language.class.php');
$lang = new Language('./languages/');
$lang->loadFile(LANGUAGE) and die('File pl.php not found'); /* including language file */
//SMARTY`s class
class smartyMailer extends Smarty {
//constract
public function __construct()
{
//simple configuration of smarty
$this->Smarty();
$this->template_dir = TEMPLATE_DIR;
$this->compile_dir = COMPILE_DIR;
$this->config_dir = CONFIG_DIR;
$this->cache_dir = CACHE_DIR;
}
}
/* END OF CONFIGURE.PHP */
?>
I know it`s very slow and I ask you how to create rapid configuration of my application. IT is very important for me because I must have prepared application for two days in Sunday.


Sign In
Create Account


Back to top









