简体   繁体   中英

Sending email with an attachment in osCommerce

I'm trying to send 2 attachments with every order (terms and conditions), but it doesn't seem to work , since I'm receiving 0kb files attached.

The permissions are correct and the files do exist.

This is the function:

function tep_mail_attach($to_name, $to_email_address, $email_subject, $email_text, $from_name, $from_email_address, $file, $filetype, $filename, $file2, $filetype2, $filename2) {

if (SEND_EMAILS != 'true') return false;

$message = new email(array('X-Mailer: osCommerce'));

$text = strip_tags($email_text);
if (email_USE_HTML == 'true') {
     $message->add_html($text);
} else {
      $message->add_text($text);
}

if(is_array($file)){
for($i=0;$i<sizeof($file);$i++){

$attachment = fread(fopen($file[$i], "r"), filesize($file[$i]));


$message->add_attachment($attachment, $filename[$i].'.'.$filetype[$i], $filetype[$i]);
}}
else{
$attachment = fread(fopen($file, "r"), filesize($file));

}
if(is_array($file2)){
for($i=0;$i<sizeof($file2);$i++){

$attachment2 = fread(fopen($file2[$i], "r"), filesize($file2[$i]));


$message->add_attachment($attachment2, $filename2[$i].'.'.$filetype2[$i], $filetype2[$i]);
}}
else{
$attachment2 = fread(fopen($file2, "r"), filesize($file2));
}

$message->add_attachment($attachment, $filename.'.'.$filetype, $filetype);
$message->add_attachment($attachment2, $filename2.'.'.$filetype2, $filetype2);


 $message->build_message();
 $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);

}

Calling the function:

tep_mail_attach($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, "AllgemeineGeschaeftsbedienungen.pdf", "pdf", "AllgemeineGeschaeftsbedienungen", "Widerrufsrecht.pdf", "pdf", "Widerrufsrecht");

I've been biting my nails on this one for the last few days, I just can't understand why the files have 0kb...

Any help is appreciated

Some time ago I've tried to make my osCommerce shop send emails in html and use attchments but I failed 'cos of awful realization of email class.

Now I'm using Mustache for php + PHPMailer . Setting up and writing wrap finctions took me couple of days, but now it's quite easy to customize mustache templates and deal with emails.

But keep in mind that instead of string concatination winthin a loop you will have to use data arrays for Mustache engine.

Now sending email looks like this (yes, I see some problems, but their solution can wait):

$mailOrederNewHtml = $mustache->render('mailOrderNew', $order);

$phpMailer->isSendmail();
$phpMailer->setFrom(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER);
$phpMailer->addAddress($order->customer['email_address'], $order->customer['firstname'] . ' ' . $order->customer['lastname']);
$phpMailer->Subject = STORE_OWNER . ' - order notofication ' . $insert_id;
$phpMailer->msgHTML($mailOrederNewHtml);
$phpMailer->WordWrap = 80;
$phpMailer->CharSet = 'utf-8';

$sendRes = $phpMailer->send();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM