This topic is locked

Mass Email

7/1/2006 9:33:22 PM
PHPRunner General questions
A
amirgulamali author

I have a table listing freinds. All emails appear as hyperlinks.. thats great, makes emailing an individual easy, now what if i want to email everyone at once? or email some selected people? like a mass mail...
any thoughts would be appreciated

Admin 7/3/2006

Amir,
just select your addresses from the database and call mail function for each address.

Here is the sample code:

global $conn;

$rs=db_query("select * from email_addresses",$conn);

while($data=db_fetch_array($rs))

{

mail($data["email"], $subject,$message);

}

A
amirgulamali author 7/3/2006

Hi ALexa,
Can u explain alil bit more, i dint get it.. call mail function where? and selectd from database meaning? I want the users of my PHP pages to be able to send mails to many people at once

Admin 7/3/2006

Amir,
you need to know some PHP to implement this.

I can recommend you to check http://www.w3schools.com website as a good start to learn PHP.
Use the code I provided you with as a sample.

A
amirgulamali author 7/3/2006

I know how to implement PHP.

I wanted alil bit of explaination of how and where to put ur code using PHPRunner-your prOduct

adamdidthis 7/3/2006

Hi Amir,
The code needs to go in a different place for the Add and edit pages. If you could give more detailas to what you want it would make it easier to help you.

A
amirgulamali author 7/3/2006

Hi Amir,

The code needs to go in a different place for the Add and edit pages. If you could give more detailas to what you want it would make it easier to help you.


thanx adam,
I have a table listing people and their emails. I want to send the same email all people in my list or send the same email to afew selected people..

Admin 7/4/2006

Amir,
you can put the email sending code to any event handler in PHPRunner.
Also you can modify the Delete feature to send emails instead of deleting records.

Here is the snippet in the ..._list.php file you'll need to change.

// delete record

if (@$_POST["mdelete"])

{

foreach(@$_POST["mdelete"] as $ind)

{
...

}

if(function_exists("AfterMassDelete"))

AfterMassDelete();

}

A
amirgulamali author 7/4/2006

i made the changes and im getting errors, undefined variables..
PHP error happened
this is my table that contains the email (and i changed the snipplet accoriding to the table name _students)
CREATE TABLE `_students` (

`entry_id` int(11) NOT NULL auto_increment,

`Username` varchar(50) default NULL,

`First Name` varchar(50) default NULL,

`Last Name` varchar(50) default NULL,

`E-mail` varchar(50) default NULL,
PRIMARY KEY (`entry_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I still want the delete funtion and want to easily send email using outlook express.. i want an email function next to the "delete selected" hyperlink
mail($data["email"], $subject,$message);
im guessing that the varibales subject and message need to be defined.. anY other peice of your snippet?

Admin 7/4/2006

Amir,

i made the changes and im getting errors, undefined variables..



Inspect your code and assign values to undefined variables.

i want an email function next to the "delete selected" hyperlink



You can do this modifying generated ..._list.php file manually.

Copy and modify the Delete button code, copy and modify the code that performs the delete operation.

You need to be familiar with PHP, HTML and Javascript in order to do this.
Unfortunately I don't have a ready to go solution for this.

A
amirgulamali author 7/4/2006

thanx alexa, i am one step ahead now..
everyone is welcome to give ideas too.. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=9628&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

A
andyjames 9/18/2006

Hi
I am trying to implement the suggested modification of the "mdelete" (delete selected records) function on the list page so that instead of deleteing selected records an email is sent to the associated email address of the selected record.

My ...list page lists a name and email address of people amongst other info.

I want to send a message to the email address for each selected record on the list page.

How is it possible to modify the following code (which only sends the same message to me@email.com for every selected record on the list page when Delete selected... (or whatever you rename it to) is clicked) so that it sends a message to the email field of each selected record.

// delete record

if (@$_POST["mdelete"])

{

foreach(@$_POST["mdelete"] as $ind)

{
$email="me@myemail.com";

$subject="Subject line";

$message="Email body";

mail($email, $subject,$message);

}

if(function_exists("AfterMassDelete"))

AfterMassDelete();

}


What I can't work out is how to return the email address where email field = same record as selected mdelete field. Can any one please help? Thanks in anticipation...

A
andyjames 9/19/2006

Hi
I have finally cracked this one (thanks for pointing me in the right direction Sergey), so if any one wants to modify the "delete selected..." link to "email selected...", this is how it goes.
This is always in the ...list.php file.

Search for the opening comment and then replace the code as follows:

// delete record

if (@$_POST["mdelete"])

{

foreach(@$_POST["mdelete"] as $ind)

{

$key=refine(@$_POST["mdelete1"][$ind-1]);

$key2=refine(@$_POST["mdelete2"][$ind-1]);

$key3=refine(@$_POST["mdelete3"][$ind-1]);



$strSQL=db_query("select email from mytable where primarykeyfield = ".$key, $conn);

if($data=db_fetch_array($strSQL))
$subject="Subject line";

$message="Email body";

mail($data["email"], $subject,$message);


}

if(function_exists("AfterMassDelete"))

AfterMassDelete();

}


mytable = table name of records displayed

email = the e-mail field name in the "mytable" table

primarykeyfield = the name of your primary key field !!
I think this will only work if you have a single primary key field. I'm guessing composite key fields need further modification...

I think you can also delete:

if(function_exists("AfterMassDelete"))

AfterMassDelete();

but I have left it to designate the end of the original code.
One more change to make...

Search for the following code:

<a href="#" onClick="if (confirm('Are you sure you wish to delete these records?')) { document.forms.deleteform.submit(); return false; } else {return true;}"><b>Delete selected...</b></a>



and replace with:

<a href="#" onClick="if (confirm('Are you sure you wish to send an e-mail to these records?')) { document.forms.deleteform.submit(); return false; } else {return true;}"><b>E-mail selected...</b></a>


Now when you check the checkboxes under the dustbin graphic, instead of deleting the selected records, you send an email to the e-mail address for that record in the email field with the subject="Subject line" and the body message="Email body".
If any one knows how to refine this so that it works for composite keys, please share...

T
thesofa 9/21/2006

Just a further twist here, will it be possible to have 3 columns of tick boxes, instead of one?

And then have three different functions applied to each column?

If so, how will I do this?

D
Dale 9/21/2006

I earlier modified the Delete function to enable a emailing to the checked items. BUT, if the user doesnt have access to Delete then the checkbox column disapppears, as it should. So the user would not be able to see the checkboxes to check for emailing.
Since then, I just added another button for my Batch Email on the list page of my customers. Now the Batch email is available even if Delete is not.
Secondly, rather than use the checkboxes to flag for an email, the Batch Email button actually calls a modified ...export.php page. There I just hacked the code to display an email template and output the email to either the current page, or all records found. Users choice.
Lastly, to avoid the problem with using the mail() function when batch emailing, I used Swift mailer to do the actual emailing. Using the mail() function and pushing hundreds of emails to the server was too much of a load for the servers. Using the Swift mailer, automatically sets up batches of a hundred emails, then a 30 sec pause and then the next batch. Currently I have 1600 customers in my batch email and all works great and an extra bonus, it runs in the background so the user can carry on after starting the batch. Swift mailer does not use the mail() function, and its blazingly fast.
You can google for Swift mailer if your interested.
Using the export page and modifying it worked better for me, the problem with using the delete checkboxes was that you would be forced to be have the complete list you wanted to batch displayed. When displaying 1600 rows in my customer list was too demanding on resources but you needed them all so you could hit the Select All to check all the boxes.
Using the export page, I could first filter the list with advanced search if needed, get the list I wanted and then call my modified export page.
This worked for me.

M
michaelmac 6/4/2007

Hi

I have finally cracked this one (thanks for pointing me in the right direction Sergey), so if any one wants to modify the "delete selected..." link to "email selected...", this is how it goes.
This is always in the ...list.php file.

Search for the opening comment and then replace the code as follows:

// delete record

if (@$_POST["mdelete"])

{

foreach(@$_POST["mdelete"] as $ind)

{

$key=refine(@$_POST["mdelete1"][$ind-1]);

$key2=refine(@$_POST["mdelete2"][$ind-1]);

$key3=refine(@$_POST["mdelete3"][$ind-1]);
$strSQL=db_query("select email from mytable where primarykeyfield = ".$key, $conn);

if($data=db_fetch_array($strSQL))
$subject="Subject line";

$message="Email body";

mail($data["email"], $subject,$message);
}

if(function_exists("AfterMassDelete"))

AfterMassDelete();

}


mytable = table name of records displayed

email = the e-mail field name in the "mytable" table

primarykeyfield = the name of your primary key field !!
I think this will only work if you have a single primary key field. I'm guessing composite key fields need further modification...

I think you can also delete:

if(function_exists("AfterMassDelete"))

AfterMassDelete();

but I have left it to designate the end of the original code.
One more change to make...

Search for the following code:

<a href="#" onClick="if (confirm('Are you sure you wish to delete these records?')) { document.forms.deleteform.submit(); return false; } else {return true;}"><b>Delete selected...</b></a>



and replace with:

<a href="#" onClick="if (confirm('Are you sure you wish to send an e-mail to these records?')) { document.forms.deleteform.submit(); return false; } else {return true;}"><b>E-mail selected...</b></a>


Now when you check the checkboxes under the dustbin graphic, instead of deleting the selected records, you send an email to the e-mail address for that record in the email field with the subject="Subject line" and the body message="Email body".
If any one knows how to refine this so that it works for composite keys, please share...


hi... I love this solution.. I think it will help me speed up the delivery of my project. I want to use it to insert the records selected into another table. I do have a short question though, what if I want to prompt the user for a short text to insert repeatedly in the table being written to.. Like their name or the Invoice Number..
Any hints?
I love this forum
Mike