Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder: Plugins & Add-ons:
emailUsers.php - cron job

 

 


gversion
User

Dec 7, 2011, 3:49 PM

Post #1 of 8 (2015 views)
Shortcut
emailUsers.php - cron job Can't Post

Hello,

I paid for some consulting time to create a plug-in that I could setup via a cron job to email users after 3 and 14 days depending on certain actions. It was either Robin or Tom that did this work I think :)

Ross as sent me the file but when I try and run it via cron I receive an error message - something is apparently wrong on Line 17...


Code
<?php 
/* This script runs from cron and determines:
1. Users who have registered but not opsted a listing (for 7 days and 14 days)
2. Users who have recieved messages from the contact form (3 days ago, 14 days ago)
3. Public who have sent message through the contact form (3 days ago, 14 days ago)

It then sends a follow-up email from the email template list specific to
that person.

(A modified version of Robins updatelistings.php)

*/

//
$placeholders = array(
'from' => $GLOBALS['SETTINGS']['adminEmail'],
'to' => $, // THIS IS LINE 17
'buyer_name' => $buyerName,
'buyer_email' => $buyerEmail,
'buyer_phone' => $buyerPhone,
'seller_name' => $sellerName,
'subject' => htmlspecialchars($_REQUEST['subject']),
'listing_id' => $_REQUEST['listing_id'],
'listing_item' => $listingsRecord['product']
);


Can you please help to fix this so I can get the file working correctly?

I'm attaching it to this post.

Thank you,
Greg
Attachments: emailUsers.php (9.64 KB)


Jason
Staff / Moderator


Dec 7, 2011, 4:35 PM

Post #2 of 8 (2014 views)
Shortcut
Re: [gversion] emailUsers.php - cron job [In reply to] Can't Post

Hi Greg,

The problem on line 17:


Code
'to'              => $,


is a PHP syntax error. There's a $ but no variable name. The additional problem is that there will also be no value for 'to' in the email.

Change this to the variable you want to send the email to. For example, if you wanted to send the email to the buyer's email, try this:


Code
'to'              => $buyerEmail,


Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


gversion
User

Dec 8, 2011, 4:21 AM

Post #3 of 8 (1981 views)
Shortcut
Re: [Jason] emailUsers.php - cron job [In reply to] Can't Post

Hi Jason,

Thanks for the response. I understand the problem.

How do I know whether I should use the buyer's or the seller's email variable? This script send automated emails to both types of users. Perhaps this section deals with the buyer and there is some other code that is used to email the seller...?

Thanks again for your help.

Regards,
Greg


gversion
User

Dec 8, 2011, 9:16 AM

Post #4 of 8 (1971 views)
Shortcut
Re: [Jason] emailUsers.php - cron job [In reply to] Can't Post

Hi Jason,

I have tried putting in the variable that you suggested:


Code
$buyerEmail


However, now I receive the following error message:


Quote
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''contacted' = 'No' ORDER BY cms_contact_seller.createdByUserNum' at line 17



I'd be extremely grateful if you could take another look at this for me.

Thank you,
Greg


Tom P
User


Dec 8, 2011, 1:50 PM

Post #5 of 8 (1956 views)
Shortcut
Re: [gversion] emailUsers.php - cron job [In reply to] Can't Post

Hello Greg,

The problem is the query is looking for a value 'No' for the field "...contacted" where it should be checking for '0'.

If you find both occurrences of


Code
AND $contactTable.contacted' = 'No'


(lines 139 and 189 in our copy of the file) and replace them with


Code
AND $contactTable.contacted' = '0'


it will eliminate this error.

With regard to the earlier missing variable question (on line 17), you should put your own email address in place of the '$'. The subsequent calls to the emailUsers function all override the 'to' variable anyway and if there is an error with the sending, it would be better for the errant email to come to you!

Hope this helps,

Tom


gversion
User

Dec 8, 2011, 2:05 PM

Post #6 of 8 (1952 views)
Shortcut
Re: [Tom P] emailUsers.php - cron job [In reply to] Can't Post

Hi Tom,

A big thank you for your help sorting that out. The cron isn't reporting any errors now, which is great.

I am going to test that the script actually sends out all the correct emails automatically, but it will take a couple of weeks for me to confirm this (as some emails aren't meant to be sent for 14 days)... unless you know of a way I can speed up the testing process?

Thanks again for your help!

Best wishes,
Greg


Tom P
User


Dec 8, 2011, 2:12 PM

Post #7 of 8 (1950 views)
Shortcut
Re: [gversion] emailUsers.php - cron job [In reply to] Can't Post

Hi Greg,

First step to test is to make a backup copy of the file as it is now (you'll need it later!).

There are four variables that set the timing for the emails:

Code
$today                = date("Y-m-d"); 
$threedaysago = date("Y-m-d", strtotime('-3 days'));
$sevendaysago = date("Y-m-d", strtotime('-1 week'));
$fourteendaysago = date("Y-m-d", strtotime('-2 weeks'));


The strings '-3 days','-1 week' and '-2 weeks' can be set to any value, for example '-1 day', with the result that the function will send emails sooner rather than later.

Furthermore, to be 'safe', you should change all references to an email address (all from and to fields) to be your email address so that only you receive any emails generated.

Once you're satisfied that everything is working, re-instate the backup copy of the file.

Hope that helps,

Tom


gversion
User

Dec 8, 2011, 4:02 PM

Post #8 of 8 (1937 views)
Shortcut
Re: [Tom P] emailUsers.php - cron job [In reply to] Can't Post

Hi Tom,

Thanks for explaining this. I will give it a shot and get back to you if I have any problems.

Regards,
Greg