Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script redirecting instead of executing 2

Status
Not open for further replies.

lifelineamerica

Programmer
Aug 9, 2006
23
US
I built a script that will send an email to a bunch of people from a list.
At each row, I have a checkbox to select whether to include that person in the mass email or no.

Funny thing that's happening is that if I choose less than 10 people to email it goes through, however if I choose anything more than 10 people I am redirected to the homepage of the site. (???)

I don't know if indeed it is PHP that's doing it, or maybe the server itself is doing it.

I figured maybe if it is PHP, then it may be related to PHP directive restrictions , though I don't see any warnings in the php.log file only a bunch of "PHP Notices".

If it would be a directive in there I can't for the life of me figure out which one it could be.

Although the emails are HTML emails and contain pictures, the size of each email is only 8.8 KB. I thought maybe post_max_size would be a trigger, but that is set to 8M which is like 100 times the size of 10 emails.
 
How can we help without knowing more about your server? Seeing your code?
 
Ok here we go.
I had to remove a bunch of code from that script that was not relevant to the problem at hand.
I created this smaller script that has just the part we need.
It's doing the exact same abortion or redirection if choosing more than 10 as explained.



<?
include("includes/settings.php");

$the_id=$_POST[each_checkbox];

for ($dd=0; $dd < count($the_id); $dd++) {


//select from the db the info where its id matches this id
$lookup_query="SELECT *, HOUR(t_time) AS rowhour,MINUTE(t_time) AS rowminutes FROM
res_reservations, res_times, res_stops, res_areas,res_groups
WHERE res_reservations.time_id=res_times.time_id
&& res_times.group_id=res_groups.group_id
&& res_stops.stop_id=res_times.stop_id
&& res_areas.area_id=res_stops.area_id
&& res_id='$the_id[$dd]'";

$lookup_result=mysql_query($lookup_query)or die(mysql_error());
$row=mysql_fetch_array($lookup_result);
$date_unix = strtotime("$row[dotrav]");
$date_searched_nice = date("l, F j Y", $date_unix);

$upfname=$row[fname];
$uplname=$row[lname];
$email=$row;
$phone=$row[phone];
$numofpeop=$row[numofseats];
$time_id=$row[time_id];
$price_per_leg=$row[price_per_leg];
$group_id=$row[group_id];
$resnum=$row[resnum];
$rowhour=$row[rowhour];
$rowminutes=$row[rowminutes];
$notes=$row[res_notes];


if ($rowminutes==0){
$rowminutes="00";
}
$amorpm="AM";
if ($rowhour>11){
$amorpm="PM";
}
if ($rowhour>12){
$rowhour=$rowhour-12;
}
//another funny exception
if (($rowhour==0)&&($rowhour!='')){
$rowhour=12;
}


$rawtime="$row[rowhour]:$row[rowminutes]:00";

$hiddentime="$rowhour:$rowminutes $amorpm";
$hiddenstop="$row[address], $row[city]";
$hiddendetails="- $row[details]";

if ($group_id!=0){
$dest_query="select * from res_stops
LEFT JOIN res_group_to_dest ON res_stops.stop_id= res_group_to_dest.dest_id
LEFT JOIN res_groups ON res_group_to_dest.group_id=res_groups.group_id WHERE res_group_to_dest.group_id=$group_id order by stop_order DESC";
$dest_result=mysql_query($dest_query);
$outresult=mysql_num_rows($dest_result);
//echo $dest_query;
//important - leave next line toi avoid concatenating all from one email to next
$eta_for_print='';
for($d=1;$d<=$outresult;$d++){
$dest_row=mysql_fetch_array($dest_result);
//default trip time is 4 hours in minutes
$eta=240;
$eta+=$dest_row[add_to_do];
$eta+=$add_to_pu;
$dest_time=date("g:i a", strtotime($rawtime)+($eta*60));
$eta_for_print.="$dest_time at $dest_row[address], $dest_row[city], - $dest_row[details]<br>";
$eta_for_plain.="$dest_time at $dest_row[address], $dest_row[city], - $dest_row[details]
";
}


//end if ($group_id!=0){ loop
}


$todayunixdate = strtotime(date("Y-m-d"));
$outunixdate = strtotime("$date_unix");
$days_difference=($todayunixdate-$date_unix)/86400;




if ($row[numofseats]==1){
$niceseats="1 seat";
}else if ($row[numofseats]>1){
$niceseats="$row[numofseats] seats";
}


//send confirmation email to customer
//Email the customer with the reservation info
//create a multipart message with HTML last
$content_cust ="\r\n--XXMail12345\r\n";
//plain text first
$content_cust .= "Content-type: text/plain; charset=iso-8859-1\r\n\r\n";
$content_cust .="Dear $upfname $uplname,

You requested that we reemail you your following valid reservation with us:


THIS IS YOUR PAID E-TICKET!!! PLEASE PRINT THIS PAGE AND BRING IT ALONG TO THE BUS
If you are unable to print, at least write down your reservation number.

Here are the details of your reservation:

Name: $upfname $uplname

Seats Reserved: $numofpeop

Departure Reservation Number: $resnum

Departure Date: $date_searched_nice

Departure Time & Place: $hiddentime from $hiddenstop $hiddendetails";
if ($outresult>1){
$content_cust .="

Destinations & approximate arrival times:
$eta_for_plain";
}else{
$content_cust .="

Destination & approximate arrival time:
$eta_for_plain";
}


$content_cust .="


==============================================

$reservation_footer";


$content_cust .= "\r\n--XXMail12345\r\n";
$content_cust .= "Content-type: text/html; charset=iso-8859-1\r\n\r\n";
ob_start();
include('../avatar2/printable_version.php');
$htmlver=ob_get_contents();
ob_end_clean();
$content_cust .=$htmlver;

$tocust ="$email";

$subjectcust ="Re-Emailing Reservation Information";
$mailheaders_cust ="From:Bus Reservations <info@whateverbuscompany.com>\n";
$mailheaders_cust .="Reply-To:info@whateverbuscompany.com\n";
$mailheaders_cust .= "MIME-Version: 1.0\n";
$mailheaders_cust .= 'Content-Type: multipart/alternative; boundary="XXMail12345";';
mail($to_cust, $subject_cust, $content_cust, $mailheaders_cust);

//close ($a=0; $a < count($the_id); $a++) loop
}




?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title><?echo "$dd emails re-emailed"?></title>
</head>

<body bgcolor="#ffffff">
<p><?echo "$dd emails re-emailed"?>
</p>
</body>

</html>
 
Well I have identified it down to the htmal email part. If I disable the HTML part of the emails and only send plain text version there's no issue.

That would break down the bug into one of theses lines then:

ob_start();
include('../avatar2/printable_version.php');
$htmlver=ob_get_contents();
ob_end_clean();
$content_cust .=$htmlver;
 
so if you are saying that something in those five lines (together with the includes()) is causing your server to fail after sending 10 html email messages then it either points to a memory issue or some other non-php related instability.

all mail() does is handoff to sendmail or its equivalent (assuming you are on *nix). it has no essential functionality of its own.

so look to your mail logs, php error logs (for memory issues), server logs and see whether anything is reported.

also, most php apps that I am aware of use phpmailer to handle their mails, from large batch sends to single mails. it provides more options/granularity and greater error reporting.

 
I wonder if your generated HTML might have too many characters in a line. That can mess with the mail output and possibly cause this to fart out. You can make it safer by word wrapping the HTML before it hits the mail function. Use the wordwrap function.

Code:
ob_start();
include('../avatar2/printable_version.php');
$htmlver=ob_get_contents();
ob_end_clean();
$htmlver = wordwrap($htmlver, 72);
$content_cust .=$htmlver;

Related discussion and example of mangled HTML output:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top