View Single Post
  #1  
Old 04-27-2006, 02:34 AM
 
MallRomania MallRomania is offline
 

Senior Member
  
Join Date: Apr 2006
Posts: 109
 

Default SMTP mail function

I ask tehnical support how can i use SMTP function to send mail...the answer is listed below (please consider this mod as a big thanks to all who create and publish free mods here)

> 1. Download PHPMailer class
> http://prdownloads.sourceforge.net/phpmailer/phpmailer-1.73.zip?download
>
> 2. Extract the archive and copy phpmailer directory to [xcart root
> directory]/include/ folder of your x-cart (for example, using FTP client).
>
> 3. Open Patch/Upgrade page of x-cart admin area, paste the following SQL query
> into Apply SQL patch memo box:
>
> insert into xcart_config values ('use_smtp', 'Use SMTP server', '', 'Email', '',
> 'checkbox', ''), ('smtp_server', 'SMTP server', '', 'Email', '', 'text', ''),
> ('smtp_user', 'SMTP AUTH username', '', 'Email', '', 'text', ''),
> ('smtp_password', 'SMTP AUTH password', '', 'Email', '', 'text', '');
>
> 4. Open include/func.php file, find definition of func_send_mail function and
> replace in the 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);


with:

//added 1
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 added 1
}


__________________________________________________ ___________
Next step: Function func_send_simple_mail:

replace:

if (preg_match('/([^ @,;<>]+@[^ @,;<>]+)/S', $from, $m))
@mail($to,$mail_subject,$mail_message,$headers, "-f".$m[1]);
else
@mail($to,$mail_subject,$mail_message,$headers);

with:


//added 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 added 2




5. Open General settings > Email options page, tick "Use SMTP server" option and
> enter server name of the SMTP server and login/password if your server requires
> SMTP authorization. Save the changes and try, for example, change customer
> profile in customer area or place an order, you should receive an email via SMTP
> server configured at the Email options page.


Note from me: keep ticked internal PHP mailer for sending newsletters and if it need add SMTP AUTH username and password, in my case it's not working without that

Also, please note that original post from tehnical department was modified meanwhile so i hope i put here all information you need

Thanks
__________________
Mircea Teleleu
Shopedia.ro-la cumparaturi
www.shopedia.ro
______________________
x-cart gold 4.1.6
Linux
Reply With Quote