osHelpers - Help for your osCommerce store
 
Google Base Feed Germany
iFrame Defender v1.2
oscommerce Seo
  Seo Pack 2
  SE Friendly URLs
  Session ID Removal
  Title and Meta Tags
  Google Sitemap
Magnum Shopping Cart
  Magnum MVS 8.4 Basic
osCommerce Services
  osc / cre patch
  Data Entry
  Data Extraction
  bugs and fixing
  Site Transfer
  creloaded Transfer
  Design Special
  Hosting
osCommerce Templates
osCommerce Contributions
  Credit Modules
  Features
  Images
  InfoBoxes
  Languages
  Order Total Modules
  Other
  Payment Modules
  Reports
  Shipping Modules
  Templates/Themes
  Zones
osCommerce Articles
osCommerce Tutorials
  Installing osCommerce
  Configuring your store
  Adding categories
  Adding products
  Adding product attributes
  Configuring currency
  Adding payment modules
  Adding shipping modules
  Configuring sales tax
  Editing your home page
  Editing columns
  Editing header and footer
  Creating specials
  Managing customers
  Sending out a newsletter
  Sending out email
  Managing your banners
  Backup database
CRELoaded Tutorials
  Add Administrators
  Add Article Author
  Additional Images
  Create a New Page
  Define Mainpage
  Disable cc Encryption
  Disable Company Field
  Disable Country
  Disable Date of Birth
  Display broken images
  Easypopulate Export
  Email confirmation
  Insert Faq
  Max Package Weight
  Require Terms of Use
  Affiliate Newsletter
  Enable Cache
CB Power Affiliate
Tell A Friend
 

Tell someone you know about this product.

   OSHELPERS | OSCOMMERCE CONTRIBUTIONS | CREDIT MODULES | 3139   


oscommerce Emailqueue
[3139]
 
 
box_bg_l.gif.
"Email queue.

one of the problems I faced was that on several occasions the response of the system was rather slow.
The main cause it seems was the email sending via smtp of the isp provider.
Checkout confirmation was one of those occasions especially if you add the additional email to the store owner.

Therefore, not being able to speed up the smtp, I decided to separate the email processing from the online
transaction. In short, I do not send the emails at that time but create them as before and store them in an email queue
to be processed later via a batch job. That job can run hourly or every minute. The main benefit is that the online
transaction and thus the site response does no longer have to wait for the php mail function to complete.


to do this the following:

1) add this new function to general.php :


function tep_store_mail($to_name, $to_email_address, $email_subject, $email_text) {
$sql_data_array = array('to_name' => $to_name,
'charset' => CHARSET,
'to_email_address' => $to_email_address,
'email_subject' => $email_subject,
'email_text' => $email_text);

tep_db_perform('email_batch', $sql_data_array);
}


2) add the new table to your database :


#
# Table structure for table 'email_batch'
#

DROP TABLE IF EXISTS email_batch;
CREATE TABLE email_batch (
email_id int(5) unsigned NOT NULL auto_increment,
charset varchar(20) default NULL,
send char(1) default 'N',
to_name varchar(50) NOT NULL default '',
to_email_address varchar(50) NOT NULL default '',
email_subject varchar(100) NOT NULL default '',
email_text text NOT NULL,
last_updated datetime default NULL,
PRIMARY KEY (email_id),
UNIQUE KEY email_id (email_id),
KEY email_id_2 (email_id),
KEY send (send)
) TYPE=MyISAM COMMENT='batch emails';



3) create the batch php job which sends the emails out email_batch_send.php


this job selects all emails not yet send, sends them and sets them to send.
You may also opt to delete them, I do not so I do not need the extra email to the store owner as I can look in the database.
I do need to make an admin management screen for this, unless there are vulanteers.
Another benefit, you can send them again and again and...

schedule this php job at your convenience.

require('includes/configure.php');
require(DIR_WS_INCLUDES . 'filenames.php');
require(DIR_WS_INCLUDES . 'database_tables.php');
require(DIR_WS_FUNCTIONS . 'database.php');
tep_db_connect() or die('We are currently unavailable due to Maintenance..');
require ('includes/configuration_cache_read.php');
require(DIR_WS_FUNCTIONS . 'general.php');
require(DIR_WS_CLASSES . 'mime.php');
require(DIR_WS_CLASSES . 'email.php');
$email_query = tep_db_query("select * from email_batch where send = 'N' ");
while ($email = mysql_fetch_array($email_query)) {
define('CHARSET', $email['charset']);
$email['email_text'] = str_replace("n", '
', $email['email_text']); // not sure why but I need this for html
tep_mail(
$email['to_name'],
$email['to_email_address'],
$email['email_subject'],
$email['email_text'],
'Crystal Light Centrum',
'services@crystallight.com.tw');
tep_db_query("update email_batch set send = 'Y', last_updated = now() where email_id = '" . $email['email_id']. "'");
}
mysql_free_result($email_query);
?>



4) everywhere where the tep_mail function is called, change that function to tep_store_mail. you can leve the parameters the same, only change the name.


5) in case of password forgotten, you may opt to keep sending the email immediately ofcourse."

 


For more information, visit the official osCommerce contribution webpage.
box_bg_r.gif.
 

osHelpers

osHelpers