View Single Post
  #5  
Old 04-28-2006, 11:02 PM
 
MallRomania MallRomania is offline
 

Senior Member
  
Join Date: Apr 2006
Posts: 109
 

Default

I have x-cart gold 4.0.18 on linux.

Here is both functions for sending mail from include/func.php


function func_send_mail($to, $subject_template, $body_template, $from, $to_admin, $crypted=false) {
global $mail_smarty, $sql_tbl;
global $config;
global $current_language, $store_language, $shop_language;
global $to_customer;
global $override_lng_code;

if (empty($to)) return;


$from = preg_replace('![\x00-\x1f].*$!sm', '', $from);

$encrypt_mail = $crypted && $config["Security"]["crypt_method"];

$lng_code = "";
if ($to_admin) {
$lng_code = ($current_language?$current_language:$config["default_admin_language"]);
}
elseif ($to_customer) {
$lng_code = $to_customer;
}
else {
$lng_code = $shop_language;
}

$charset = func_query_first_cell ("SELECT charset FROM $sql_tbl[countries] WHERE code='$lng_code'");
$override_lng_code = $lng_code;

$mail_smarty->assign_by_ref ("config", $config);

if ($config["Email"]["html_mail"] == "Y" && !$encrypt_mail) {
# Select HTML-style templates is this option is enabled.
if (file_exists($mail_smarty->template_dir."/mail/html/".basename($body_template))) {
$mail_smarty->assign("mail_body_template","mail/html/".basename($body_template));
$body_template = "mail/html/html_message_template.tpl";
}
}
$mail_message = func_display($body_template,$mail_smarty,false);
$mail_subject = chop(func_display($subject_template,$mail_smarty,f alse));

if (X_DEF_OS_WINDOWS) {
$mail_message = preg_replace("/(?<!\r)\n/", "\r\n", $mail_message);
$lend = "\r\n";
}
else
$lend = "\n";

$files = array();
if($config["Email"]["html_mail"] == "Y") {
list($mail_message, $tmp) = func_attach_images($mail_message);
if(!empty($tmp)) {
foreach($tmp as $k => $v)
$files[] = $v;
}
}

if($encrypt_mail)
$mail_message = func_pgp_encrypt ($mail_message);

if ($config["Email"]["html_mail"] == "Y" && !$encrypt_mail)
$message_header = "Content-Type: text/html; charset=".$charset.$lend;
else
$message_header = "Content-Type: text/plain; charset=".$charset.$lend;
$message_header .= "Content-Disposition: inline".$lend."Content-Transfer-Encoding: 8bit".$lend;

if(!empty($files) && is_array($files)) {
$boundary = substr(uniqid(time()."_"), 0, 16);
$mail_message = "--".$boundary.$lend.$message_header.$mail_message.$l end;
$message_header = "Content-Type: multipart/related; boundary=\"$boundary\"".$lend;
foreach($files as $k => $v) {
$mail_message .= "--".$boundary.$lend;
$mail_message .= "Content-Type: $v[type]; name=\"$v[name]\"".$lend;
$mail_message .= "Content-Disposition: inline; filename=\"$v[name]\"".$lend;
$mail_message .= "Content-Transfer-Encoding: base64".$lend;
$mail_message .= "Content-ID: <$v[name]>".$lend;
$mail_message .= $lend.chunk_split(base64_encode($v['data'])).$lend;
}
$mail_message .= "--".$boundary."--".$lend;
}

$m_from = $from;
if ($config["Email"]["use_base64_headers"] == "Y")
$mail_subject = func_mail_quote($mail_subject,$charset);

$headers = "From: ".$m_from.$lend."X-Mailer: PHP/".phpversion().$lend."MIME-Version: 1.0".$lend.$message_header;
if (trim($m_from) != "")
$headers .= "Reply-to: ".$m_from.$lend;
//old function
//if (preg_match('/([^ @,;<>]+@[^ @,;<>]+)/S', $from, $m))
//@mail($to,$mail_subject,$mail_message,$headers, "-f".$m[1]);
//else
//@mail($to,$mail_subject,$mail_message,$headers);
//end old
//adaugat
if ($config['Email']['use_smtp'] == 'Y') {
if (empty($config['Email']['smtp_server'])) {
return;
}

global $xcart_dir;
require_once $xcart_dir."/include/phpmailer/class.smtp.php";

$smtp = new SMTP();
#$smtp->do_debug = true;
if (!$smtp->Connect($config['Email']['smtp_server'])) {
$smtp->Close();
return false;
}
if (!$smtp->Hello()) {
$smtp->Close();
return false;
}
if (!empty($config['Email']['smtp_user'])) {
if (!$smtp->Authenticate($config['Email']['smtp_user'], $config['Email']['smtp_password'])) {
$smtp->Close();
return false;
}
}
if (!$smtp->Mail($m_from)) {
$smtp->Close();
return false;
}
$recipients = preg_split("/[,\s]+/", $to);
$recipients = array_map("trim", $recipients);
foreach ($recipients as $r) {
if (empty($r)) {
continue;
}
if (!$smtp->Recipient($r)) {
$smtp->Close();
return;
}
}
if (!$smtp->Data("To:" . $to . $lend . "Subject: " . $mail_subject.$lend.$headers.$lend.$mail_message)) {
$smtp->Close();
return;
}
$smtp->Quit();
$smtp->Close();
} else {
if (preg_match('/([^ @,;<>]+@[^ @,;<>]+)/S', $from, $m))
@mail($to,$mail_subject,$mail_message,$headers, "-f".$m[1]);
else
@mail($to,$mail_subject,$mail_message,$headers);
}
//end adaugat
}

__________________________________________________ __________



function func_send_simple_mail($to, $subject, $body, $from) {
global $config;
global $current_language;
global $sql_tbl;

if (empty($to)) return;


$from = preg_replace('![\x00-\x1f].*$!sm', '', $from);

if (X_DEF_OS_WINDOWS) {
$body = preg_replace("/(?<!\r)\n/", "\r\n", $body);
$lend = "\r\n";
}
else
$lend = "\n";

if (!empty($current_language))
$charset = func_query_first_cell ("SELECT charset FROM $sql_tbl[countries] WHERE code='$current_language'");

if (empty($charset))
$charset = func_query_first_cell ("SELECT charset FROM $sql_tbl[countries] WHERE code='".$config["default_admin_language"]."'");

if ($config["Email"]["use_base64_headers"] == "Y") {
$m_from = $from;
$m_subject = func_mail_quote($subject,$charset);
}
else {
$m_from = $from;
$m_subject = $subject;
}

$headers = "From: ".$m_from.$lend."X-Mailer: PHP/".phpversion().$lend;
if (trim($m_from) != "")
$headers .= "Reply-to: ".$m_from.$lend;

$headers .= "MIME-Version: 1.0".$lend;
if ($config["Email"]["html_mail"] == "Y")
$headers .= "Content-Type: text/html; charset=".$charset.$lend;
else
$headers .= "Content-Type: text/plain; charset=".$charset.$lend;

//if (preg_match('/([^ @,;<>]+@[^ @,;<>]+)/S', $from, $m))
//@mail($to,$m_subject,$body,$headers, "-f".$m[1]);
//else
//@mail($to,$m_subject,$body,$headers);
//adaugat 2
if ($config['Email']['use_smtp'] == 'Y') {
if (empty($config['Email']['smtp_server'])) {
return;
}

global $xcart_dir;
require_once $xcart_dir."/include/phpmailer/class.smtp.php";

$smtp = new SMTP();
#$smtp->do_debug = true;
if (!$smtp->Connect($config['Email']['smtp_server'])) {
$smtp->Close();
return false;
}
if (!$smtp->Hello()) {
$smtp->Close();
return false;
}
if (!empty($config['Email']['smtp_user'])) {
if (!$smtp->Authenticate($config['Email']['smtp_user'], $config['Email']['smtp_password'])) {
$smtp->Close();
return false;
}
}
if (!$smtp->Mail($m_from)) {
$smtp->Close();
return false;
}
$recipients = preg_split("/[,\s]+/", $to);
$recipients = array_map("trim", $recipients);
#echo "<pre><h1>RECIPIENTS:"; var_dump($recipients); echo "</h1></pre>";
foreach ($recipients as $r) {
if (empty($r)) {
continue;
}
if (!$smtp->Recipient($r)) {
$smtp->Close();
return;
}
}
if (!$smtp->Data("To:" . $to . $lend . "Subject: " . $m_subject.$lend.$headers.$lend.$body)) {
$smtp->Close();
return;
}
$smtp->Quit();
$smtp->Close();
} else {
if (preg_match('/([^ @,;<>]+@[^ @,;<>]+)/S', $from, $m))
@mail($to,$mail_subject,$mail_message,$headers, "-f".$m[1]);
else
@mail($to,$mail_subject,$mail_message,$headers);
}
//end adaugat 2
}
__________________
Mircea Teleleu
Shopedia.ro-la cumparaturi
www.shopedia.ro
______________________
x-cart gold 4.1.6
Linux
Reply With Quote