I am trying to execute one of my scripts. This is a contact script that processes encodings when sending emails using the jQuery ajax function.
I wanted the user to be able to use the same script with two forms on the same page and make it an easy job.
Now I have made a prototype of how this will be rewritten to fit.
It was really strange for me, but I study every day. The hardest part for me is where should I place my methods and how to make a thread script.
To demonstrate what I mean, here are some parts of the code I'm using now:
public function __construct($data, $config = array()) {
$lang = isset($config['language']) ? $config['language'] : 'en';
$this->_getPhrases($lang);
$this->_recieverEmail = isset ($config['reciever_email']) ? filter_var($config['reciever_email'], FILTER_SANITIZE_EMAIL) : die($this->_phrase['noRecieverEmail']);
$this->_ajax = ($this->_enableAjax($config['ajax_enabled'])) ? true : false;
$this->_data = isset($data) ? (is_array($data) ? $data : die($this->_phrase['errors']['dataNotArray'])) : $_POST;
}
public function send() {
if(!$this->isDataVaild($this->_data)) {
return false;
}
$this->_data = $this->_cleanData($this->_data);
$this->setSenderName($this->_data['name']);
$this->setSenderEmail($this->_data['email']);
$this->_message = $this->_generateMsg($this->data);
$PHPMailer = new PHPMailerLite();
$this->_sendUsing($PHPMailer, $this->_message);
return true;
}
I chose these two methods specifically because they do most of the work for my script. I use it like this:
$config = array(
'language' => 'en',
'ajax_enabled' => false,
'reciever_email' => 'recieve@localhost'
);
$contact = new coolContact($_POST, $config);
if($contact->send()) {
echo 'Message sent with No problems';
} else {
echo $contact->getErrors();
}
, :
send() _generateMsg()?- oop php?
1 , :
, , , oop, , . , .