This script will cycle through the specified list(s) and send the welcome message, loaded from each list, to each user on the list who has not already received it. It is designed to be run every 5 or 10 minutes via cron.
This script is useful when using plugins for aMember, aShop or your own custom insert scripts that add users to ListMail but don't send the welcome message.
1. Copy the following code into a new .PHP file, such as "sendwelc.php".
2. Modify the file to contain a new password and the lists you want to use it on.
3.
Important: If you are already using "user1" as a custom field on your lists, change the value of the $custom_field variable to a value between "user1" and "user10" (for custom fields 1 thru 10) to a field not used on
any list.
4. Save your changes and upload the file to your main ListMail directory. We use /mail as an example.
5. If you want to flag all current users as having received the welcome message run the "install" script by browsing to
http://yoursite.com/mail/sendwelc.php?pw=yourpassword&install=1
6. Set up a new cron task to load the script every 5 or 10 minutes
Every 5 minutes:
0-59/5 * * * * /usr/bin/wget -O /dev/null
http://yoursite.com/mail/sendwelc.php?pw=yourpassword 1> /dev/null 2> /dev/null
Every 10 minutes:
0-59/10 * * * * /usr/bin/wget -O /dev/null
http://yoursite.com/mail/sendwelc.php?pw=yourpassword 1> /dev/null 2> /dev/null
<?php/* Script to send welcome messages via cron command, storing a "1" in the user1 field (Custom Field 1) if the message has already been sent. */// CONFIG$mypw = "0137724e";// lists, separated by commas$lists = "1,2,3,5,7";// only change if you're already using the default custom field on one or more of your lists$custom_field = "user1";// output on$output = 1;// End of Config / Begin Script// ListMail includes$lmpath = ".";include($lmpath."/config.php");include($lmpath."/admin.php");// check pwif($_GET['pw']<>$mypw) exit('Incorrect Password');// 'install' script, set all current users to 'already sent'// to run browse to sendwelc.php?pw=PASS&install=1if($_GET['install']=='1'){ $lists2 = explode(',',$lists); $cmd = "update $utable set $custom_field = '1' where "; while(list($k,$l)=each($lists2)){ if($k<>0) $x = ' or '; else $x = ''; $cmd .= $x."list = '$l'"; } if($output) echo "Install: Setting all current users to 'sent'<br>SQL=$cmd<br><br>"; mysql_query($cmd);}// select lists$lists2 = explode(',',$lists);while(list($k,$l)=each($lists2)){ // select users $urows = mysql_query("select id,email from $utable where list = '$l' and $custom_field <> '1';"); if(@mysql_num_rows($urows)>0){ while(list($id,$em)=mysql_fetch_row($urows)){ if($output) echo "Sending welcome message to $em on list $l<br>"; sendwelcome($id); mysql_query("update $utable set $custom_field = '1' where id = '$id';"); } } else { if($output) echo "No users to send to on list $l<br>"; }}echo "Done!<br>";?>
Enjoy!