Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Attachment in admin email


Guest

Recommended Posts

Is there someone that can help me.

 

I downloaded the following contribution because i want to send a newsletter in pdf file.

 

http://addons.oscommerce.com/info/4583

 

I dont get it because one way or the other it is not working.

 

The attachment is not getting sended.

 

I´ll add the php files from my website.

 

MAIL.PHP

 

<?php>
/*
 $Id: mail.php 1739 2007-12-20 00:52:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

 $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

 if ( ($action == 'send_email_to_user') && isset($HTTP_POST_VARS['customers_email_address']) && !isset($HTTP_POST_VARS['back_x']) ) {
switch ($HTTP_POST_VARS['customers_email_address']) {
  case '***':
	$mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS);
	$mail_sent_to = TEXT_ALL_CUSTOMERS;
	break;
  case '**D':
	$mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");
	$mail_sent_to = TEXT_NEWSLETTER_CUSTOMERS;
	break;
  default:
	$customers_email_address = tep_db_prepare_input($HTTP_POST_VARS['customers_email_address']);

	$mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($customers_email_address) . "'");
	$mail_sent_to = $HTTP_POST_VARS['customers_email_address'];
	break;
}

$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']);
$mimemessage = new email(array('X-Mailer: osCommerce'));

if (isset($GLOBALS['userfile']) && tep_not_null($GLOBALS['userfile']))
   {  $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);
   }

$mimemessage->add_text($message);
$mimemessage->build_message();
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)));
 }

 if ( ($action == 'preview') && !isset($HTTP_POST_VARS['customers_email_address']) ) {
$messageStack->add(ERROR_NO_CUSTOMER_SELECTED, 'error');
 }

 if (isset($HTTP_GET_VARS['mail_sent_to'])) {
$messageStack->add(sprintf(NOTICE_EMAIL_SENT_TO, $HTTP_GET_VARS['mail_sent_to']), 'success');
 }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
 <tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
</table></td>
<!-- body_text //-->
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
		<td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
 if ( ($action == 'preview') && isset($HTTP_POST_VARS['customers_email_address']) ) {
switch ($HTTP_POST_VARS['customers_email_address']) {
  case '***':
	$mail_sent_to = TEXT_ALL_CUSTOMERS;
	break;
  case '**D':
	$mail_sent_to = TEXT_NEWSLETTER_CUSTOMERS;
	break;
  default:
	$mail_sent_to = $HTTP_POST_VARS['customers_email_address'];
	break;
}
?>
	  <?php echo tep_draw_form('mail', FILENAME_MAIL, 'action=send_email_to_user','post','enctype="multipart/form-data"'); ?>
		<td><table border="0" width="100%" cellpadding="0" cellspacing="2">
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td class="smallText"><b><?php echo TEXT_CUSTOMER; ?></b><br><?php echo $mail_sent_to; ?></td>
		  </tr>
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td class="smallText"><b><?php echo TEXT_FROM; ?></b><br><?php echo htmlspecialchars(stripslashes($HTTP_POST_VARS['from'])); ?></td>
		  </tr>
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td class="smallText"><b><?php echo TEXT_SUBJECT; ?></b><br><?php echo htmlspecialchars(stripslashes($HTTP_POST_VARS['subject'])); ?></td>
		  </tr>
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td class="smallText"><b><?php echo TEXT_MESSAGE; ?></b><br><?php echo nl2br(htmlspecialchars(stripslashes($HTTP_POST_VARS['message']))); ?></td>
		  </tr>
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
<tr>
<td class="smallText"><b><?php echo TEXT_ATTACHMENT; ?></b><br><input name="userfile" type="file"></td>
</tr>
<tr>
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
</tr>
		  </tr>
		  <tr>
			<td>
<?php
/* Re-Post all POST'ed variables */
reset($HTTP_POST_VARS);
while (list($key, $value) = each($HTTP_POST_VARS)) {
  if (!is_array($HTTP_POST_VARS[$key])) {
	echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
  }
}
?>
			<table border="0" width="100%" cellpadding="0" cellspacing="2">
			  <tr>
				<td><?php echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="back"'); ?></td>
				<td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_MAIL) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a> ' . tep_image_submit('button_send_mail.gif', IMAGE_SEND_EMAIL); ?></td>
			  </tr>
			</table></td>
		  </tr>
		</table></td>
	  </form></tr>
<?php
 } else {
?>
	  <tr><?php echo tep_draw_form('mail', FILENAME_MAIL, 'action=preview'); ?>
		<td><table border="0" cellpadding="0" cellspacing="2">
		  <tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
<?php
$customers = array();
$customers[] = array('id' => '', 'text' => TEXT_SELECT_CUSTOMER);
$customers[] = array('id' => '***', 'text' => TEXT_ALL_CUSTOMERS);
$customers[] = array('id' => '**D', 'text' => TEXT_NEWSLETTER_CUSTOMERS);
$mail_query = tep_db_query("select customers_email_address, customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " order by customers_lastname");
while($customers_values = tep_db_fetch_array($mail_query)) {
  $customers[] = array('id' => $customers_values['customers_email_address'],
					   'text' => $customers_values['customers_lastname'] . ', ' . $customers_values['customers_firstname'] . ' (' . $customers_values['customers_email_address'] . ')');
}
?>
		  <tr>
			<td class="main"><?php echo TEXT_CUSTOMER; ?></td>
			<td><?php echo tep_draw_pull_down_menu('customers_email_address', $customers, (isset($HTTP_GET_VARS['customer']) ? $HTTP_GET_VARS['customer'] : ''));?></td>
		  </tr>
		  <tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo TEXT_FROM; ?></td>
			<td><?php echo tep_draw_input_field('from', EMAIL_FROM); ?></td>
		  </tr>
		  <tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo TEXT_SUBJECT; ?></td>
			<td><?php echo tep_draw_input_field('subject'); ?></td>
		  </tr>
		  <tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td valign="top" class="main"><?php echo TEXT_MESSAGE; ?></td>
			<td><?php echo tep_draw_textarea_field('message', 'soft', '60', '15'); ?></td>
		  </tr>
		  <tr>
			<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td colspan="2" align="right"><?php echo tep_image_submit('button_send_mail.gif', IMAGE_SEND_EMAIL); ?></td>
		  </tr>
		</table></td>
	  </form></tr>
<?php
 }
?>
<!-- body_text_eof //-->
	</table></td>
  </tr>
</table></td>
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

This is the text of the contribution.

 

Description:

This contribution will allow you to send email to customers with an attachment included (from the admin panel) , there are no filetype or size limitations. 
Only the store administrator will be able to use this option. 

Requeriments:

A] Your hosting provider must allow uploads, go to your administration panel and click on "Tools" then click on "Server Info" (left menu) and search for:

file_uploads On On 

If it's off then switch hosting providers.

B] Using a FTP program, set '777' as permission to folder "download" inside catalog."catalog" is your store's root folder.

Procedure:

1] Go to: 'catalog\admin\includes\languages\english\mail.php'
2] add

define('TEXT_ATTACHMENT','File attachment:');

3] Go to: 'catalog\admin\includes\languages\espanol\mail.php'
4] add 

define('TEXT_ATTACHMENT','Archivo adjunto:');

5] Go to: 'catalog\admin\includes\configure.php' 
6] add

define('DIR_FS_DOWNLOAD', DIR_FS_CATALOG . 'download/');

7] Go to: 'catalog\admin\mail.php'
8] Search for (line 35 or so): 

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

9] Delete or comment the next lines until you reach: 

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

10] Add this code into that place (note that this code starts with [8] and ends with [9]) :

$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']);
$mimemessage = new email(array('X-Mailer: osCommerce'));

if (isset($GLOBALS['userfile']) && tep_not_null($GLOBALS['userfile']))
   {  $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);
   }

$mimemessage->add_text($message);
$mimemessage->build_message();
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)));


11] At the same file (catalog\admin\mail.php) Search for (line 135 or so):

<tr>
<td class="smallText"><b><?php echo TEXT_MESSAGE; ?></b><br><?php echo nl2br(htmlspecialchars(stripslashes($HTTP_POST_VARS['message']))); ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
</tr>

12] Add after it:

<tr>
<td class="smallText"><b><?php echo TEXT_ATTACHMENT; ?></b><br><input name="userfile" type="file"></td>
</tr>
<tr>
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
</tr>

13] Enjoy!


NOTE: The add attachment option will be visible on the EMAIL CONFIRMATION SCREEN (This is the SECOND screen that appears when you click on "send mail" at the "Send Email To Customers" screen).
Remember, on the "Send Email To Customers" screen choose your destination emails, type subject and message, then click on "send mail" and the add attachment option will appear on the next screen.

This was tested with .rar, .doc, .xls and .pdf files without problems, should work for others too. Hotmail and Gmail accounts received and downloaded the attachment without problems. 

If you dont want to include an attachment just leave the file upload field blank (dont choose a file). The email will be sent without attachment as it does by default.


Have a great day!

Link to comment
Share on other sites

  • 1 year later...

i use that too and that really not work at the online mode..but in off line mode that function just can upload file to the download directory....... :angry:

 

i tough no body here care about it cause no one can make it fix i have been workin' on it 3 days and i got no thing... :lol:

 

and i tough i not the one how stupid... :lol: :lol: :lol: :lol: :lol: :lol: :lol:

Link to comment
Share on other sites

  • 2 weeks later...

HOT HOT HOT HOT HOT HOT HOT HOT HOT HOT HOT

 

i have just success send my second attachment from my osCommerce admin panel mail......i have tired twice sent to yahoo mail and that work bloody fine....

 

actually i use it in my own function i call extra mail but if you don't use it you can usu in mail.php hope this help and enjoy this...he

 

first find:

if (isset($GLOBALS['userfile']) && tep_not_null($GLOBALS['userfile'])){

$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

//'unreal.zip'

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);

}

 

and replace with:

 

//Kill the if function for make the attachment work fine -- Nabler rastaman http://www.plazamalang.com

//if (isset($GLOBALS['userfile']) && tep_not_null($GLOBALS['userfile'])){

$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

//'unreal.zip'

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);

//}

 

second:

find:

<?php echo tep_draw_form('mail', FILENAME_MAIL, 'action=send_email_to_user'); ?>

and replace with:

<?php echo tep_draw_form('mail', FILENAME_MAIL, 'action=send_email_to_user','enctype="multipart/form-data"'); ?>

 

 

 

:lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...