Jump to content

Question about sending mails with files attached.

Recommended Posts

Hi, Because I'd like to send emails to customers with files attached (doing from Administrator). And later on, to enhance my website giving the customers the opportunity to send me mails with attachments, I though to start by having the Add-On number (4583) (http://addons.oscommerce.com/info/4583)


Although a simple Add On it works partially on my OSC 2.3.1. ... It sends the message but without the attachment. Despite I feel confident enough to do small coding, I'm not an expert in the subject.

I would appreciate to have some advice from the experts in this forum about what could be wrong.


In my 'future' website, to let the customers send information back to our designers, is a very useful functionality. So I will appreciate all your help on this simple stuff. I spend a whole day digging on this but....without success :-(


This Add-On modifies the catalog\admin\mail.php file. The code updated to let send the attachment is:


$from = tep_db_prepare_input($HTTP_POST_VARS['from']);

$subject = tep_db_prepare_input($HTTP_POST_VARS['subject']);

$message = tep_db_prepare_input($HTTP_POST_VARS['message']);

//Let's build a message object using the email class

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


if ($_FILES['userfile']['size'] > 0) {


$attachment_name = $HTTP_POST_FILES['userfile']['name'];

$attachment_type = $HTTP_POST_FILES['userfile']['type'];

//$attachment_size = $HTTP_POST_FILES['userfile']['size']; //Just in case you want to check and limit the size

new upload('userfile', DIR_FS_DOWNLOAD);

$attachment_file = DIR_FS_DOWNLOAD . $attachment_name;

$attachments = $mimemessage->get_file($attachment_file);

$mimemessage->add_attachment($attachments, $attachment_name, $attachment_type);



// Build the text version

$text = strip_tags($message);

if (EMAIL_USE_HTML == 'true') {

$mimemessage->add_html($message, $text);

} else {





while ($mail = tep_db_fetch_array($mail_query)) {

$mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', $from, $subject);



tep_redirect(tep_href_link(FILENAME_MAIL, 'mail_sent_to=' . urlencode($mail_sent_to)));



I've also attached to this message the whole mail.php I use.


Thank-you very much in ahead of time.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now