This topic is locked

Sending emails from the database

1/21/2007 4:31:50 AM
PHPRunner General questions
I
ictaylor author

Hi
I have a database full of information and demographics of the people who have entered their details. How do I send them all the same email to the email addresses providedby them in the database?
any help with the code would be appreciated
cheers

J
Jane 1/22/2007

Hi,
you can do it using events.

Proceed to the Events tab, select ViewOnLoad event and add your code in it.

Here is a sample:

function ViewOnLoad()

{

global $where,$strTableName,$conn;

$str = "select * from ".$strTableName." where ".$where;

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$email=$data["EmailFieldName"];

$message="Hello there\nBest regards";

$subject="Sample subject";

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

}



where EmailFieldName is your actual field name where email is stored.

I
ictaylor author 1/23/2007

Hi,

you can do it using events.

Proceed to the Events tab, select ViewOnLoad event and add your code in it.

Here is a sample:
where EmailFieldName is your actual field name where email is stored.


Thanks Jane,
Perhaps you can help me further - I am a little unsure as to how to get this to work. My database is full of email addresses in the 'email' field which I created in phprunner - I dont understand about going to the 'events' tab you mention as my database is already uploaded and I dont want to risk losing anything or losing how I have changed the format - I thought if i did this it would reupload all the pages and thus lose the changes I have made (ie colour etc) and defer to default?
I was rather looking for a php script to upload on a separate page that I can go to in my browser and perform this function.
Do I copy the code you kindly provided (with <? ?> and database connection data at the top)above and name it as a .php and then visit where I upload it and it'l just send the message for me to all the email addresses in the specified field?
Also how do I format the text in the $message?

J
Jane 1/23/2007

Hi,
apply this code on the Events tab in the PHPRunner (step 11) and then build your project.

In this case email with all info will be sent when you open your view page.
PHPRunner can not create script emailed all records from database.
This task can be accomplished using some simple PHP script or application.

However it has no connection with PHPRunner.