83 lines
2.9 KiB
PHP
83 lines
2.9 KiB
PHP
<?php
|
|
|
|
// Make sure we are called from index.php
|
|
if (!defined('SECURITY'))
|
|
die('Hacking attempt');
|
|
|
|
class Mail extends Base {
|
|
function checkStmt($bState) {
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
if ($bState ===! true) {
|
|
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
|
$this->setErrorMessage('Internal application Error');
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Mail form contact site admin
|
|
* @param senderName string senderName
|
|
* @param senderEmail string senderEmail
|
|
* @param senderSubject string senderSubject
|
|
* @param senderMessage string senderMessage
|
|
* @param email string config Email address
|
|
* @param subject string header subject
|
|
* @return bool
|
|
**/
|
|
public function contactform($senderName, $senderEmail, $senderSubject, $senderMessage) {
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
if (preg_match('/[^a-z_\.\!\?\-0-9\\s ]/i', $senderName)) {
|
|
$this->setErrorMessage('Username may only contain alphanumeric characters');
|
|
return false;
|
|
}
|
|
if (empty($senderEmail) || !filter_var($senderEmail, FILTER_VALIDATE_EMAIL)) {
|
|
$this->setErrorMessage( 'Invalid e-mail address' );
|
|
return false;
|
|
}
|
|
if (preg_match('/[^a-z_\.\!\?\-0-9\\s ]/i', $senderSubject)) {
|
|
$this->setErrorMessage('Subject may only contain alphanumeric characters');
|
|
return false;
|
|
}
|
|
if (strlen(strip_tags($senderMessage)) < strlen($senderMessage)) {
|
|
$this->setErrorMessage('Your message may only contain alphanumeric characters');
|
|
return false;
|
|
}
|
|
$aData['senderName'] = $senderName;
|
|
$aData['senderEmail'] = $senderEmail;
|
|
$aData['senderSubject'] = $senderSubject;
|
|
$aData['senderMessage'] = $senderMessage;
|
|
$aData['email'] = $this->setting->getValue('website_email');
|
|
$aData['subject'] = 'Contact From';
|
|
if ($this->sendMail('contactform/body', $aData)) {
|
|
return true;
|
|
} else {
|
|
$this->setErrorMessage( 'Unable to send email' );
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function sendMail($template, $aData) {
|
|
$this->smarty->assign('WEBSITENAME', $this->setting->getValue('website_name'));
|
|
$this->smarty->assign('SUBJECT', $aData['subject']);
|
|
$this->smarty->assign('DATA', $aData);
|
|
$headers = 'From: Website Administration <' . $this->setting->getValue('website_email') . ">\n";
|
|
$headers .= "MIME-Version: 1.0\n";
|
|
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
|
|
if (mail($aData['email'], $this->smarty->fetch(BASEPATH . 'templates/mail/subject.tpl'), $this->smarty->fetch(BASEPATH . 'templates/mail/' . $template . '.tpl'), $headers))
|
|
return true;
|
|
$this->setErrorMessage('Unable to send mail');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Make our class available automatically
|
|
$mail = new Mail ();
|
|
$mail->setDebug($debug);
|
|
$mail->setMysql($mysqli);
|
|
$mail->setSmarty($smarty);
|
|
$mail->setConfig($config);
|
|
$mail->setSetting($setting);
|
|
?>
|