Author Topic: Send Welcome Messages Script  (Read 5792 times)

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Send Welcome Messages Script
« on: July 08, 2005, 09:16:16 pm »
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

Code: [Select]
<?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 pw
if($_GET['pw']<>$mypw) exit('Incorrect Password');

// 'install' script, set all current users to 'already sent'
// to run browse to sendwelc.php?pw=PASS&install=1
if($_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!  8)
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

lewis.wolk

  • Posts: 11
    • View Profile
Works like a charm Dean!
« Reply #1 on: July 09, 2005, 09:45:29 am »
Dean,
Only thing is I have no welcome messages only follow ups on all my lists.
So I guess I have two choices If you do not add in a toggle to only send followups instead of welcome message.

Once is copy my first follow up as the welcome message ande delete number one follow up from each lists.

Or add just a quick e-mail welcome message that more mail will follow .
What do you think ?

Lewis

lewis.wolk

  • Posts: 11
    • View Profile
Dean not working for me :(
« Reply #2 on: July 09, 2005, 10:08:40 am »
Dean,
ran some tests and the e-mails are being sent correctly however it is pulling the correct header ie Subject but the actual txt seems to be always what is in list 1 welcome message.

Plz advise
lewis

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Send Welcome Messages Script
« Reply #3 on: July 09, 2005, 08:07:57 pm »
I have not been able to recreate this.  In my testing, I set up my list 1 welcome message to say "list 1" in both the subject and  message, and list 2 the same, with "list 2" in the subject and message.

I set up two users, one on each list, to receive message sent by the script.  I ran the script and received the proper messages with the proper subject lines.

Are you absolutely sure your other lists' welcome messages are not the same as your list 1 one?

The welcome message is intended to be sent instantly, with followups being sent in the following days.  You can do what you suggested, remove the first followup and put it in as the welcome message, and ListMail should work the same, sending the remaining followups in the days that follow.

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

lewis.wolk

  • Posts: 11
    • View Profile
oops how dumb am I :)
« Reply #4 on: July 10, 2005, 10:32:27 am »
Dean,
On further investigation what was happeneing is the text messages were all correct however I had copied and pasted all the html messages from the original thank you and this is what I was receiving once I fixed it things were perfect.

But I am wndering something .
Now that I did as you said and changed my first follow up to be the welcome message it is being sent instantly.

So did lmpro actualy do this from the start and I missed it by NOT having any welcome messages and only having followups ?

Lewis

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Send Welcome Messages Script
« Reply #5 on: July 10, 2005, 07:52:33 pm »
Lewis,

If enabled and set up on a list, the welcome message will be sent instantly, optionally when manually adding or importing and automatically if a user subscribes from a ListMail form on your web site.

aShop, as far as I know, does not send the welcome message when it inserts a ListMail user with its plugin.

It is not recommended that you use the above script on lists that use aShop AND have the welcome message enabled (unless you set custom field 1 to "1" to indicate the welcome message was sent), as this will result in duplicate welcome messages to some users.

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting

lewis.wolk

  • Posts: 11
    • View Profile
Send Welcome Messages Script
« Reply #6 on: July 15, 2005, 08:42:25 am »
Dean,
Exactly whats happenening to me is the system is sending duplicate mesasges. So to make sure I understand since I am using your script every 10 minutes I should disable the elwcome message and move the welocme message to be the first followup instead of being the welcome message ?
Then the script will send the first followup immedeatly ?????

This is the part I do not understand.
p.s. I only use listmail with ashop.

Lewis

Quote from: "DW"
Lewis,

If enabled and set up on a list, the welcome message will be sent instantly, optionally when manually adding or importing and automatically if a user subscribes from a ListMail form on your web site.

aShop, as far as I know, does not send the welcome message when it inserts a ListMail user with its plugin.

It is not recommended that you use the above script on lists that use aShop AND have the welcome message enabled (unless you set custom field 1 to "1" to indicate the welcome message was sent), as this will result in duplicate welcome messages to some users.

Regards

DW

  • Administrator
  • Posts: 3787
    • View Profile
    • https://legacy.listmailpro.com
Send Welcome Messages Script
« Reply #7 on: July 15, 2005, 10:06:18 am »
Lewis,

The welcome message is sent "immediately" by the custom script.  If you have the same information set up in your first followup it will again be sent, next dailymail, so it should be removed.

I hope this clears up the problem!

Regards
Dean Wiebe
ListMailPRO Author & Developer - Help | Support | Hosting