Multiple E-mailing Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zimick7
Forum Newbie
Posts: 17
Joined: Mon Dec 06, 2004 2:11 pm

Multiple E-mailing Script

Post by zimick7 »

I have put together an event registration script for youth events at our church. When the youth is registered, I would like to e-mail the youth, the parent, and a notification to the youth office.

The problem is this: I am allowing for up to 4 to register at a time (in case a parent has four youth...). These are entered into a MySQL database and then recalled for confirmation. At this time, the youth is/are officially registered.

I have found that when testing four registering at a time, I only receive e-mails for two of the test-youth (set my e-mail address for all youth and parent e-mail). The other two youth e-mails never get to me. Also, the notification e-mail sent to the youth office only includes 1 youth.

Currently, if four youth are registering at a time, the code goes through a while command. Therefore, with four youth, 12 e-mails are sent with the script (4 to youth, 4 to the parent (for each youth), and 4 to the office (for each youth).

In actuallity, only 5 of the e-mails are going through.

What could be causing this problem? All my code is correct (I believe). Any help would be appreciated.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

[magic-ball] :p a sample of your loop and your call to mail would come in handy
zimick7
Forum Newbie
Posts: 17
Joined: Mon Dec 06, 2004 2:11 pm

Post by zimick7 »

timvw wrote:[magic-ball] :p a sample of your loop and your call to mail would come in handy

Code: Select all

<?php

***connect to database***

$query = "SELECT * FROM register WHERE id='$id' or id='$id2' or id='$id3' or id='$id4'";
$result = mysql_query($query);
while($data = mysql_fetch_array($result))
	{
	
	$id = $data[id];
	$eventname = $data[event];
	$fname = $data[fname];
	$lname = $data[lname];
	$address = $data[address];
	$city = $data[city];
	$zip = $data[zip];
	$phone = $data[phone];
	$semail = $data[semail];
	$pemail = $data[pemail];
	$grade = $data[grade];
	$shirt = $data[shirt];
	$sex = $data[sex];
	$friend1 = $data[friend1];
	$friend2 = $data[friend2];
	
	echo "[id: $id] <b>$fname $lname</b> registered for $eventname<br>";
	
 //Sends e-mail to student, parent, and youth sec.

 mail("$semail", "You Are Registered for $eventname", "$fname,\nThank you for registering online for $eventname", "From: youthpastor@somechurch.org\n");
 mail("$pemail", "$fname $lname Registered for $eventname", "Your youth, $fname $lname, was registered online for $eventname", "From: youthpastor@somechurch.org\n");

 mail("registration@somechurch.org", "New Registration", "New Registration!\n$eventname\n\nName: $fname $lname\nAddress: $address\n$city, TN $zipcode\nPhone Number: $phone\n
 Student E-mail Address: $semail\nParent E-mail Address: $pemail\n
 Grade: $grade\nT-shirt Size: $shirt\nSex: $sex\nRequested Students: $friend1, $friend2", "From: registrations@somechurch.org\n");





$filepointer = fopen("/path/to/registrationfile.txt","a"); //appends to end of file

fwrite($filepointer,"<b>Event:</b> $eventname <br>");
fwrite($filepointer,"<b>Name:</b> $firstname ");
fwrite($filepointer,"$lastname<br>");
fwrite($filepointer,"<b>Address:</b> $address<br>");
fwrite($filepointer,"$city,TN ");
fwrite($filepointer,"$zip<br>");
fwrite($filepointer,"<b>Phone Number: </b>($phone)");
fwrite($filepointer,"<b>Student E-mail Address: </b>$semail<br>");
fwrite($filepointer,"<b>Parent E-mail Address: </b>$pemail<br>");
fwrite($filepointer,"<b>Grade: </b>$grade<br>");
fwrite($filepointer,"<b>T-Shirt Size: </b>$shirt<br>");
fwrite($filepointer,"<b>Sex: </b>$sex<br>");
fwrite($filepointer,"<b>Requested Students: </b>$friend1, ");
fwrite($filepointer,"$friend2<br><hr>");

fclose($filepointer);


$insert = "UPDATE register SET complete='yes' WHERE id='$id'";
mysql_query($insert);
	}

?>
Anybody help?
zimick7
Forum Newbie
Posts: 17
Joined: Mon Dec 06, 2004 2:11 pm

Post by zimick7 »

Sorry if my code is sloppy; i did not even know any PHP two weeks ago.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

zimick7 wrote:

Code: Select all

$id = $data[id];
it is cleaner and more efficient to write $data['id'];
or you could use [php_man]extract[/php_man]($data);
this will generate variables like: $id, $event, $fname, ...
zimick7 wrote:

Code: Select all

mail("$semail", "You Are Registered for $eventname", "$fname,\nThank you for registering online for $eventname", "From: youthpastor@somechurch.org\n");
headers are always \r\n instead of \n.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

The problem might be a spam filter. Some stop emails if various with the same subject are send or received in a small timeframe
zimick7
Forum Newbie
Posts: 17
Joined: Mon Dec 06, 2004 2:11 pm

Post by zimick7 »

I thought that was a possible reason. Thanks for the info.
Post Reply