// MERGE with 1.4 r7770
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7776 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+46
-18
@@ -32,7 +32,7 @@ include_once(_PS_SWIFT_DIR_.'Swift/Plugin/Decorator.php');
|
||||
|
||||
class MailCore
|
||||
{
|
||||
static public function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_)
|
||||
public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_, $die = false)
|
||||
{
|
||||
$configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
|
||||
if(!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
|
||||
@@ -42,26 +42,42 @@ class MailCore
|
||||
if (!isset($fromName)) $fromName = $configuration['PS_SHOP_NAME'];
|
||||
|
||||
if (!empty($from) AND !Validate::isEmail($from))
|
||||
die(Tools::displayError('Error: parameter "from" is corrupted'));
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "from" is corrupted'), $die);
|
||||
return false;
|
||||
}
|
||||
if (!empty($fromName) AND !Validate::isMailName($fromName))
|
||||
die(Tools::displayError('Error: parameter "fromName" is corrupted'));
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "fromName" is corrupted'), $die);
|
||||
return false;
|
||||
}
|
||||
if (!is_array($to) AND !Validate::isEmail($to))
|
||||
die(Tools::displayError('Error: parameter "to" is corrupted'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($templateVars))
|
||||
die(Tools::displayError('Error: parameter "templateVars" is not an array'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "templateVars" is not an array'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do not crash for this error, that may be a complicated customer name
|
||||
if (!empty($toName) AND !Validate::isMailName($toName))
|
||||
$toName = NULL;
|
||||
|
||||
if (!Validate::isTplName($template))
|
||||
die(Tools::displayError('Error: invalid email template'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid email template'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Validate::isMailSubject($subject))
|
||||
die(Tools::displayError('Error: invalid email subject'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid email subject'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Construct multiple recipients list if needed */
|
||||
if (is_array($to))
|
||||
@@ -72,7 +88,10 @@ class MailCore
|
||||
$to_name = NULL;
|
||||
$addr = trim($addr);
|
||||
if (!Validate::isEmail($addr))
|
||||
die(Tools::displayError('Error: invalid email address'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid email address'), $die);
|
||||
return false;
|
||||
}
|
||||
if ($toName AND is_array($toName) AND Validate::isGenericName($toName[$key]))
|
||||
$to_name = $toName[$key];
|
||||
$to_list->addTo($addr, $to_name);
|
||||
@@ -89,8 +108,10 @@ class MailCore
|
||||
if ($configuration['PS_MAIL_METHOD'] == 2)
|
||||
{
|
||||
if (empty($configuration['PS_MAIL_SERVER']) OR empty($configuration['PS_MAIL_SMTP_PORT']))
|
||||
die(Tools::displayError('Error: invalid SMTP server or SMTP port'));
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
|
||||
return false;
|
||||
}
|
||||
$connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl") ? Swift_Connection_SMTP::ENC_SSL : (($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls") ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
|
||||
$connection->setTimeout(4);
|
||||
if (!$connection)
|
||||
@@ -109,7 +130,10 @@ class MailCore
|
||||
/* Get templates content */
|
||||
$iso = Language::getIsoById((int)($id_lang));
|
||||
if (!$iso)
|
||||
die (Tools::displayError('Error - No ISO code for email'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
|
||||
return false;
|
||||
}
|
||||
$template = $iso.'/'.$template;
|
||||
|
||||
$moduleName = false;
|
||||
@@ -128,8 +152,10 @@ class MailCore
|
||||
$overrideMail = true;
|
||||
}
|
||||
elseif (!file_exists($templatePath.$template.'.txt') OR !file_exists($templatePath.$template.'.html'))
|
||||
die(Tools::displayError('Error - The following email template is missing:').' '.$templatePath.$template.'.txt');
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error - The following email template is missing:').' '.$templatePath.$template.'.txt', $die);
|
||||
return false;
|
||||
}
|
||||
$templateHtml = file_get_contents($templatePath.$template.'.html');
|
||||
$templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath.$template.'.txt'), NULL, 'utf-8'));
|
||||
|
||||
@@ -161,7 +187,7 @@ class MailCore
|
||||
catch (Swift_ConnectionException $e) { return false; }
|
||||
}
|
||||
|
||||
static public function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
|
||||
public static function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
|
||||
{
|
||||
$swift = NULL;
|
||||
$result = NULL;
|
||||
@@ -201,13 +227,15 @@ class MailCore
|
||||
*
|
||||
* @param string $string raw sentence (write directly in file)
|
||||
*/
|
||||
static public function l($string, Context $context = null)
|
||||
static public function l($string, $id_lang = null, Context $context = null)
|
||||
{
|
||||
global $_LANGMAIL;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
|
||||
$key = str_replace('\'', '\\\'', $string);
|
||||
if ($id_lang == null)
|
||||
$id_lang = (!isset($context->language) OR !is_object($context->language)) ? (int)Configuration::get('PS_LANG_DEFAULT') : (int)$context->language->id;
|
||||
|
||||
$file_core = _PS_ROOT_DIR_.'/mails/'.$context->language->iso_code.'/lang.php';
|
||||
if (Tools::file_exists_cache($file_core) && empty($_LANGMAIL))
|
||||
|
||||
Reference in New Issue
Block a user