Jump to content
Sign in to follow this  
Jack_mcs

AutoEmailer

Recommended Posts

It looks like your host made a change in its php version. The code casuing that problem needs to be rewritten to get rid of the error but you can do so, as the text says

If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file

 

Jack

Share this post


Link to post
Share on other sites

Is there a way to make this work with TinyMCE instead of FCK Editor?


Powered By osC 2.2RC2a STS 4.5.8 - HTC 2.6.3 - FP 1.5.9 - BCH 1.0.0

Share this post


Link to post
Share on other sites

Jack,

 

when the birthday email is sent to a customer, the sender's (From:) address is sometimes multiplied by 25 approximately. It looks like:

 

From: info@mysite.com, info@mysite.com,info@mysite.com,info@mysite.com,info@mysite.com,info@mysite.com,

 

Any idea what might be causing it?


Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites
Is there a way to make this work with TinyMCE instead of FCK Editor?
Yes, in fact I prefer TinyMCE but it wasn't a ready when this contribution came out. To use it, you would need to convert the tep_draw_fckeditor calls to standard oscommerce ones and include the TinyMCE code in the <head> section as described in that contribution.

 

Jack

Share this post


Link to post
Share on other sites
Jack,

 

when the birthday email is sent to a customer, the sender's (From:) address is sometimes multiplied by 25 approximately. It looks like:

 

From: info@mysite.com, info@mysite.com,info@mysite.com,info@mysite.com,info@mysite.com,info@mysite.com,

 

Any idea what might be causing it?

I haven't seen this problem and can't see how it can happen with the code the way it is. Does it happen for any customer? If not, then maybe there are some duplicate emails in the database. It seems unliklely but that's all I can think of at the moment.

 

Jack

Share this post


Link to post
Share on other sites

It only happens to some customers. When tested, I received birthday email to my gmail just fine but replies from some customers look like this:

 

Original Message -----
From: info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com; info@mysite.com
To: markXXXX@comcast.net
Sent: Tuesday, May 08, 2007 8:01 AM
Subject: Your Birthday Gift from My Site

As you can see, there is 19 From: email addresses (I just replaced it with mysite obviously). Unfortunately (or fortunately) I do not receive that many replies to those birthday emails. Sometimes it's all fine, but sometimes there was minimum six and maximum 25 copies of the address. Could the number be related to the number of emails sent that day? Very weird... and little bit annoying. What could be causing it? The code that sends it is this, correct?:

 

$customers_query = mysql_query("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address, ci.customers_info_date_account_created, ci.customers_info_id from customers c, customers_info ci where c.customers_id = ci.customers_info_id") or die(mysql_error());

 $adjYr =  substr($currentDate, 0, 4);
 $adjMth = (int)substr($currentDate, 5, 2);
 $adjMth = str_pad($adjMth, 2, "0", STR_PAD_LEFT);

 while ($customer = mysql_fetch_array($customers_query, MYSQL_ASSOC))
 {
// Start Date Selection
  $adjDate = sprintf("%s-%s-%s", $adjYr, substr($customer['customers_dob'], 5, 2),substr($customer['customers_dob'], 8, 2));
// Stop Date Selection
  $diff = DifferenceBetween($currentDate, $adjDate);
// Start Date Difference
  if ($diff >= 0 && $diff < 1)
// Stop Date Difference
  {
// Start Subject
	   $Subject = 'Your Birthday Gift from My Site';
// Stop Subject		 
	 $Recipiant = $customer['customers_email_address'];
	 $tmessage = new Email($Recipiant, $Sender, $Subject, $CustomHeaders);
	 $tmessage->Cc = $Cc;
	 $tmessage->Bcc = $Bcc;

	 $message = '
	 <html>
	  <head>
	   <title>Happy birthday</title>
	  </head>
	  <body>
	  <p>Dear ' . $customer['customers_firstname'] . ',<br><br>

<!-- start message //-->  
<u>test</u> your   <strong>message</strong> here<br />	 now
<!-- stop message //-->

	 </body>
	 </html>
	 ';

// Mail it
	 $tmessage->SetHtmlContent($message);
	 $serverFileMimeType = 'text/html';
	 $tmessage->SetFileContent($pathToServerFile, $serverFileMimeType);
//		 $tmessage->Send();
// changed to \n instead of \r\n below - otherwise no html - mr_absinthe
	 $headers .= 'MIME-Version: 1.0' . "\n";
	 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
	 $headers .= 'From: info@mysite.com' . "\n";
	  mail($Recipiant, $Subject, $message, $headers);		 
  }
 }
?>


Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites

Yes, that is the code. It is reading all of the customers information and then checks the date (that really should be in the sql command). If it falls within that date, it sends an email to that one address. So I don't see how it can be adding more than one address per customer.

 

Jack

Share this post


Link to post
Share on other sites

Hi, Great contrib, I found because today is my birthday and I received an email from a forum I am a member of and thought about adding this type of thing to our online store and found this. I can get the emails to work perfectly when running from the browser but cron throws me the following error email (The path up to admin has been removed) . . .

 

/admin/auto_emailer/auto_emailer.php: line 1: ?php: No such file or directory

/admin/auto_emailer/auto_emailer.php: line 2: /aquota.user: Permission denied

/admin/auto_emailer/auto_emailer.php: line 3: $: command not found

/admin/auto_emailer/auto_emailer.php: line 4: AutoEmailer: command not found

/admin/auto_emailer/auto_emailer.php: line 5: osCommerce,: command not found

/admin/auto_emailer/auto_emailer.php: line 6: http://www.oscommerce.com: No such file or directory

/admin/auto_emailer/auto_emailer.php: line 8: syntax error near unexpected token `c'

/admin/auto_emailer/auto_emailer.php: line 8: ` Copyright © 2002 osCommerce'

 

it is obviously reading the file but something is causing it to not run it as it should, any ideas what I need to do to my set up to make it work??

 

actual code from /admin/auto_emailer/auto_emailer.php is as follows:

<?php
/*
 $Id$
 AutoEmailer by Jack_mcs at www.oscommerce-solution.com
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2002 osCommerce

 Released under the GNU General Public License
*/
 include('class.Email.php');
 include('../includes/configure.php');

 $link = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die("Could not connect");
 mysql_select_db(DB_DATABASE);

 //Set some common items
 $Sender = 'binky@binkycrafts.com';
 $Recipiant = 'test@binkycrafts.com';
 $Cc = '';
 $Bcc = '';
 $currentDate = date('Y-m-d'); //or enter a date in the form of yyyy-mm-dd

 include('date_functions.php');

// Start modules 
include('auto_newproducts.php');
// Stop modules

 mysql_close($link);
?>


Tony

Share this post


Link to post
Share on other sites

Just adding another reply because I did not enable email notifications and could not work out how to turn them on once I had posted - is there any hope ???

Tony.


Tony

Share this post


Link to post
Share on other sites

another quick question . . I want to add a greeting in the "birthday" email using the customers first name but am not sure how to code this into the $message?

 

I tried adding this:

$firstname = $customer['customers_firstname'];

 

before the $message = '.... and then after:

<!-- start message //-->

 

I had:

<p>Hi <?php echo $firstname ?>,</p>

 

as my opening line but this only sends "Hi ," in the email

 

Hope someone can spot the rookie mistake :-D

 

Thanks,

Tony.


Tony

Share this post


Link to post
Share on other sites

The failures you are getting are most likely due to your hosts settings or how the cron job is formatted. You should ask your host about the errors.

 

For the greeting, try placing it before $message = '.

 

Jack

Share this post


Link to post
Share on other sites
Having problem setting up autoemailer please help getting this error with FCKeditor installed

 

 

Warning: main(../../admin/FCKeditor/fckeditor.php): failed to open stream: No such file or directory in /home/xxxxxxxxxx/public_html/admin/includes/functions/html_output.php on line 12

 

Warning: main(../../admin/FCKeditor/fckeditor.php): failed to open stream: No such file or directory in /home/xxxxxxxxx/public_html/admin/includes/functions/html_output.php on line 12

 

Fatal error: main(): Failed opening required '../../admin/FCKeditor/fckeditor.php' (include_path='.:/usr/local/lib/php') in /home/xxxxxxxxxx/public_html/admin/includes/functions/html_output.php on line 12

 

 

in my html_output i have this 'home/xxxxxxxxx/public_html/admin/FCKeditor/');

 

thank you

 

try this one:

 

require(DIR_FS_ADMIN . '/fckeditor/fckeditor.php');

 

fckeditor not FCKeditor ^^

Share this post


Link to post
Share on other sites

Hi Jack,

 

my auto emailer was working fine until recently, however it cannot connect to the database for some reason now.

 

I was trying to call auto_emailer/auto_emailer.php from admin with this path ../includes/configure.php and it is working fine, however it fails when executed via cron. I was also trying to use include(DIR_FS_ADMIN . 'includes/configure.php'); but id did not work either. It keeps throwing the error.

 

Any ideas what might be wrong?


Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites

Most likely, your host changed something that has affected the cron job. It isn't uncommon for cron jobs to have problems after cpanel updates, assuming that is what you are using, although it may happen with others too. You can ask your host to check it, if your host is one that will do such things.

 

Jack

Share this post


Link to post
Share on other sites
Most likely, your host changed something that has affected the cron job. It isn't uncommon for cron jobs to have problems after cpanel updates, assuming that is what you are using, although it may happen with others too. You can ask your host to check it, if your host is one that will do such things.

Jack

Jack,

 

we are still unable to make it work, perhaps you can help. To see and test if it is working, I've created a test file that was placed in admin root:

<?php
ini_set('display_errors','1');
/*
 $Id$
 AutoEmailer by Jack_mcs at www.oscommerce-solution.com
 Released under the GNU General Public License
*/
 include('auto_emailer/class.Email.php');
 include('includes/configure.php');

// option 2 $dbh used instead of $ link
 $dbh=mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die('Cannot connect to the database because: ' . mysql_error());
 mysql_select_db(DB_DATABASE);

 //Set some common items
 $Sender = 'test@site.com';
 $Recipiant = 'test@site.com';
 $Cc = '';
 $Bcc = '';
 $currentDate = date('Y-m-d'); //or enter a date in the form of yyyy-mm-dd

 include('auto_emailer/date_functions.php');

// Start modules 
include('auto_emailer/auto_announce_test.php');
// Stop modules
 echo 'The birthday seems to work now - this is test only!'."\r\n";
 mysql_close($link);
?>

The above file is in admin root and works fine when executed via cron job. However when I place the file in admin/auto_emailer/ folder and execute it via cron, it doesn't work, with the following error: Cannot connect to the database because: Unknown MySQL server host 'DB_SERVER' (1)

The file is almost identical, changed paths obviously, it works when executed from the admin site of the store:

<?php
ini_set('display_errors','1');
/*
 $Id$
 AutoEmailer by Jack_mcs at www.oscommerce-solution.com
 Released under the GNU General Public License
*/
 include('class.Email.php');
 include('../includes/configure.php');

// option 2 $dbh used instead of $ link
 $dbh=mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die('Cannot connect to the database because: ' . mysql_error());
 mysql_select_db(DB_DATABASE);

 //Set some common items
 $Sender = 'test@site.com';
 $Recipiant = 'test@site.com';
 $Cc = '';
 $Bcc = '';
 $currentDate = date('Y-m-d'); //or enter a date in the form of yyyy-mm-dd

 include('date_functions.php');

// Start modules 
include('auto_announce_test.php');
// Stop modules
 echo 'The birthday seems to work now - this is test only!'."\r\n";
 mysql_close($link);
?>


Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites

I don't see why it would fail. But you could hard-code those items, DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD and DB_DATABASE, to see if that makes a difference.

 

Jack

Share this post


Link to post
Share on other sites

Thank you for your swift reply, it all works fine. But it should also work without hard-coding them, don't you think?


Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites

Ok I got this to work now I'm wondering what is in the persons mind when they developed this to send My Customer report to all of my customers. and I'm wondering where is my order report going?

 

$customer

 

Not

 

$customers

Share this post


Link to post
Share on other sites

Sorry I was a bit flustered I should offer an explanation there.

I was trying to get this contrib working and was pulling my hair out when i notices that the line

 

$Recipiant = $customers['customers_email_address'];

 

was suppose to be

 

$Recipiant = $customer['customers_email_address'];

 

That got it to work but I found out that all my customers were getting my customer report. I would watch out for that people. I only noticed because I had a test account in Oscommerce. anyone have a fix for that. Also I don't see my orders report coming out anywhere.

Share this post


Link to post
Share on other sites

Hi Jack,

 

this is probably php5 related: I'm receiving this warning after the cron job is executed:

 

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/xxxxxxx/public_html/admin/auto_emailer.php on line 32

 

Can it be changed to get rid of that warning please?


Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites
Hi Jack,

 

this is probably php5 related: I'm receiving this warning after the cron job is executed:

 

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/xxxxxxx/public_html/admin/auto_emailer.php on line 32

 

Can it be changed to get rid of that warning please?

I don't see anything wrong with it, other than there isn't any checking done in the code so it might be failing and not handling the error correctly. Try changing this line

mysql_select_db(DB_DATABASE);

to

mysql_select_db(DB_DATABASE, $link);

If it still fails try changing this line

mysql_close($link);

to

mysql_close();

 

Jack

Share this post


Link to post
Share on other sites

Jack,

 

thank you for your quick reply, this is the solution that is working now:

I changed this:

$dbh=mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die('Cannot connect to the database because: ' . mysql_error());

mysql_select_db(DB_DATABASE, $link);

To this:

$link = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die("Unable to connect to database");

mysql_select_db(DB_DATABASE);

And after that the

mysql_close($link);
is not causing any warning.

Absinthe Original Liquor Store

Share this post


Link to post
Share on other sites

Thanks Jack, for your myriad awesome enhancements!

Whilst testing admin/auto_emailer/auto_announce.php, it appeared that the entire list of customers are returned on the initial $customers_query, then the results are searched for upcoming birthdays, (at least it was in my case)

then it occurred to moi that it might be useful for the storeowner to have advance notice of who(m) was having a birthday like the day before, so combining these 2 items, the auto_announce.php was copied and renamed auto_reminder_birthday.php and modified to send the store owner an email the day before and the initial query was changed to only bring back customers whose birthday matched the month-day search string, in the spirit of osCOM(merce)RADERIE, here is what I did-

 

oh, just in case - this worked for my version of oscommerce (osCommerce Online Merchant v2.2 RC2a)

 

1. make a copy of admin/auto_emailer/auto_announce.php

 

2. rename the copy - auto_reminder_birthday.php

 

3. replace code in NEW auto_reminder_birthday.php

LOOK FOR:

$customers_query = mysql_query("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address, ci.customers_info_date_account_created, ci.customers_info_id from customers c, customers_info ci where c.customers_id = ci.customers_info_id") or die(mysql_error());

 

$adjYr = substr($currentDate, 0, 4);

$adjMth = (int)substr($currentDate, 5, 2);

$adjMth = str_pad($adjMth, 2, "0", STR_PAD_LEFT);

 

while ($customer = mysql_fetch_array($customers_query, MYSQL_ASSOC))

{

// Start Date Selection

$adjDate = sprintf("%s-%s-%s", $adjYr, substr($customer['customers_dob'], 5, 2),substr($customer['customers_dob'], 8, 2));

// Stop Date Selection

$diff = DifferenceBetween($currentDate, $adjDate);

 

// Start Date Difference

if ($diff >= 0 && $diff < 77)

// Stop Date Difference

{

// Start Subject

$Subject = 'test' . ' ' . $customer['customers_firstname'] . ' ' . $customer['customers_lastname'];

// Stop Subject

$Recipiant = $customer['customers_email_address'];

 

REPLACE WITH: (ordinarily I'd suggest commenting it out but since this is a copy, I simply replaced it)

// 10-15-09 mod to send advance notice to store owner of upcoming birthday

$result = mysql_query("SELECT configuration_value FROM configuration WHERE configuration_key = 'STORE_OWNER_EMAIL_ADDRESS'");

if (!$result) {

echo 'Could not run query: ' . mysql_error();

exit;

}

$row = mysql_fetch_row($result);

 

$store_owner_email_address = $row[0];

echo $row[0]; // the email value

 

$adjYr = substr($currentDate, 0, 4);

$adjMth = (int)substr($currentDate, 5, 2);

$adjMth = str_pad($adjMth, 2, "0", STR_PAD_LEFT);

$adjDay = (int)substr($currentDate, 8, 2);

 

// increment day to show birthdays for tomorrow can be changed to give more advance notice eg 7 for a weeks notice

$adjDay = $adjDay +1 ;

// echo 'adjDay = ' . $adjDay . '<br />';

$searchdate = $adjMth . '-' . $adjDay;

// echo 'searchdate = ' . $searchdate . '<br />';

// search customers_dob by month and day using LIKE for any occurences

$searchdate = '%' . $searchdate . '%';

 

// THIS PART IS NOTES OF CHANGES- can be deleted

// 10-15-09 original before search for specific date rather than retrieve whole table $customers_query = mysql_query("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address, ci.customers_info_date_account_created, ci.customers_info_id, c.customers_sponsor_email from customers c, customers_info ci where c.customers_id = ci.customers_info_id") or die(mysql_error());

// substring didn't work for moi $customers_query = mysql_query("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address, ci.customers_info_date_account_created, ci.customers_info_id, c.customers_sponsor_email from customers c, customers_info ci where c.customers_id = ci.customers_info_id AND substring(c.customers_dob,5,5) LIKE '$searchdate'") or die(mysql_error());

// X THIS PART IS NOTES OF CHANGES- can be deleted

 

$customers_query = mysql_query("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address, ci.customers_info_date_account_created, ci.customers_info_id, c.customers_sponsor_email from customers c, customers_info ci where c.customers_id = ci.customers_info_id AND c.customers_dob LIKE '$searchdate'") or die(mysql_error());

 

while ($customer = mysql_fetch_array($customers_query, MYSQL_ASSOC))

{

$cusdob = substr($customer['customers_dob'],5,5);

 

// to test

echo "customer = " . $customer['customers_lastname'] . ' cusdob = ' . $cusdob;

 

// Start Date Selection

$adjDate = sprintf("%s-%s-%s", $adjYr, substr($customer['customers_dob'], 5, 2),substr($customer['customers_dob'], 8, 2));

// Stop Date Selection

$diff = DifferenceBetween($currentDate, $adjDate);

 

// Start Date Difference

if ($diff >= 0 && $diff < 77)

// Stop Date Difference

{

// Start Subject

$cfirst_name = $customer['customers_firstname'];

$clast_name = $customer['customers_lastname'];

 

$cdob = $customer['customers_dob'];

// echo 'current date = ' . $currentDate;

/*** another date ***/

$tdate = $currentDate;

//$bday = date("m/d");

$currentmonth = date('M',strtotime($currentDate));

$year = date('Y',strtotime($currentDate));

$byear = date('Y',strtotime($cdob));

$month = date('M',strtotime($cdob));

$day = date('d',strtotime($cdob));

// UNTESTED conditional to increment year if current date is in December and birthday is in January

if ($currentmonth == "Dec" && $month == "Jan") {

$year = $year + 1;

}

$birthday = $year . '-' . $month . '-' . $day;

$weekday = date('l', strtotime($birthday)); // note: first arg to date() is lower-case L

$bday = $weekday . ', ' . $month . ' ' . $day;

//echo 'bday = ' . $bday;

/*** show the date ***/

$age = $year - $byear;

 

$Subject = 'Reminder - ' . $cfirst_name . ' ' . $clast_name . ' will celebrate their ' . $age . 'th Birthday on ' . $bday . '.';

 

// orig $Subject = 'test' . ' ' . $customer['customers_firstname'] . ' ' . $customer['customers_lastname'];

// Stop Subject

// this is a new field in customers to use another email to be notified with instead of store owners email $Recipiant = $customer['customers_sponsor_email'];

$Recipiant = $store_owner_email_address;

// X 10-15-09 mod to send advance notice to store owner of upcoming birthday

 

4. in admin/auto_emailer.php

LOOK FOR:

// Start modules

ADD UNDERNEATH

// 10-15-09 mod to send advance notice to store owner of upcoming birthday

include('auto_reminder_birthday.php');

// X 10-15-09 mod to send advance notice to store owner of upcoming birthday

 

5. Save these files, upload

6. TEST by calling in browser: changing URL to match your website and admin folder name

http(s)://CHANGE_TO YOUR_WEBSITE.COM!/YOUR_ADMIN_FOLDER(hopefully not called admin for security purposes)/auto_emailer/auto_emailer.php

 

You should get an echo of results and an email sent to the store owner email address.

 

I also added a field to customers table called customers_sponsor_email which can be used to designate a different email address if such a situation arose...

There are a few echo statement to show results which can then be commented out or deleted

The conditional IF to increment the year for December/January is untested because, well you know, right?

 

Hope I touched all the bases,

jk

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
Sign in to follow this  

×