This topic is locked
[SOLVED]

 emails after record edit

5/3/2012 2:18:23 AM
PHPRunner General questions
S
stiven author

Hello everyone,
I have a table that i use to set up schedules after the record is save i want to send and email to everyone who has been schedule letting them now that they have been schedule i have a template for the email and the code for this but when i hit save the page stays loading and nothing happens, it just stays loading. i hope you can help me, this is the code i use, is there something wrong with it?


global $conn;


$coro = explode(",",$values['chorus']);
$musicos = explode(",",$values['musicians']);
array_push($coro,$values['lead']);
$people = array_merge($coro,$musicos);
$count = count($people) -1;
$arr = explode("-",$values['date']);

$service_date = $arr[1]."/".$arr[2]."/".$arr[0];

$link = '<a href="http://www.worship.mycasadevida.com/services_list.php"; style="color:#099;font-size:24px;font-weight:bold">VIEW SCHEDULE</a>';

$subject = "CASA DE VIDA WORSHIP SERVICE ".$service_date;

$from = "From: Casa De Vida Worship<worship@mycasadevida.com>\n";
// load email template

$email_message = file_get_contents("email_template.txt");
$i = 0;

while ($i <= $count){
$sql = "SELECT name,email FROM users WHERE name = '".$people[$i]."'";

$res = db_query($sql,$conn);

$row = db_fetch_array($res);
// replace variables

$email_message = str_replace("##service_date##",$service_date,$email_message);

$email_message = str_replace("##name##",$row['name'],$email_message);

$email_message = str_replace("##practice##","Thursday at 7:30 pm.",$email_message);

$email_message = str_replace("##link##",$link,$email_message);

// send HTML email

runner_mail(array('to' => $row['email'], 'subject' => $subject, 'htmlbody' => $email_message, 'charset' => 'UTF-8'));
}
C
cgphp 5/3/2012

Check firebug for errors.

S
stiven author 5/3/2012

no errors on firebug

C
cgphp 5/3/2012

Check the path of the "email_template.txt" file.

S
stiven author 5/3/2012



Check the path of the "email_template.txt" file.


hello Cristian the path is correct. this code works if i take it out of the while loop like this. this will send email to only one person but inside the while loop it does not work.



$i = 0;

//while ($i <= $count){
$sql = "SELECT name,email FROM users WHERE name = '".$people[$i]."'";

$res = db_query($sql,$conn);

$row = db_fetch_array($res);
$arr = explode("-",$values['date']);

$service_date = $arr[1]."/".$arr[2]."/".$arr[0];

$link = '<a href="http://www.worship.mycasadevida.com/services_list.php"; style="color:#099;font-size:24px;font-weight:bold">VIEW SCHEDULE</a>';

$subject = "CASA DE VIDA WORSHIP SERVICE ".$service_date;

$from = "From: Casa De Vida Worship<worship@mycasadevida.com>";
// load email template

$email_message = file_get_contents("email_template.txt");

// replace variables

$email_message = str_replace("##service_date##",$service_date,$email_message);

$email_message = str_replace("##name##",$row['name'],$email_message);

$email_message = str_replace("##practice##","Thursday at 7:30 pm.",$email_message);

$email_message = str_replace("##link##",$link,$email_message);

// send HTML email

runner_mail(array('from' => $from, 'to' => $row['email'], 'subject' => $subject, 'htmlbody' => $email_message, 'charset' => 'UTF-8'));


I just found out when in the while loop it sends the email only to the first person and it loops i dont know how many times because i got about 1000 emails

S
stiven author 5/3/2012

I found the mistake i forgot the $i++; at the end of the loop :/ my bad... thanks