one mail function to multiple user with different categories

one mail function to multiple user with different categories

Page 1 of 1

1 Replies - 1535 Views - Last Post: 17 June 2009 - 01:42 AM Rate Topic: -----

#1 chitara  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 89
  • Joined: 16-December 05

one mail function to multiple user with different categories

Posted 17 June 2009 - 01:13 AM

hi,

I have developed a script where user from different categories will inform there promotional activities to different clients via one mail function.

Let me make it more clear. Say Seller A, B sell book and seller C, D sell Computer parts. On the other hand Buyer M, N want to buy Book and Buyer X, Y want to Buy Computer parts. They got register mentioning their specific category. After certain time like once in a week a mail will be send to their specific desire buyers.

but I am getting 500 Internal Server Error and and I ask my server authority to help me. They said that the ISE is due to bad headers.

I have 2 tables(actually 3, coz the 3rd one is less important) for Seller and 2 tables for Buyer. Also sending my script for your better understanding.

<?php
	/*ini_set("log_errors","1");
	ini_set ("display_errors", "1");
	error_reporting(E_ALL);*/
	include("includes/connection.php");
	include("includes/config.php");
	//define(max_alert_page,6);
	$total_sent=0;
	$row_add="";
	$root_path="http://www.buyerxpo.com";
	$max_alert_page2=6;

$failed_mail ="";
$succeed_mail ="";
?>

			
<?

/****************all seller search block*****************/
$buyer_query="select * from buyer b, buyer_profile bf where b.BuyerID=bf.BuyerID";
//echo "<br>$buyer_query";
$buyer_result=mysql_query($buyer_query);
while($buyer_row=mysql_fetch_array($buyer_result))
{
$buyer_keywords=$buyer_row['KeyProducts'];
$buyer_mail=$buyer_row['BusinessEmail'];
$buyer_name=$buyer_row['FirstName']." ".$buyer_row['LastName'];
$buyer_ind=$buyer_row['IndustryID'];
$q="select * from categories where IndustryID='$buyer_ind' ";
$r=mysql_query($q);
$cats_all=array();
while($ar=mysql_fetch_array($r))
{
$cats_all[count($cats_all)]=$ar['CategoryID'];
}

$i=0;
$row_add="";
$sf="a,b";

/*if($buyer_keywords!='')
{
$query1="select COUNT(*) as num FROM seller s, seller_profile sp,selling_leads sl,categories c where  s.SellerID=sp.SellerID and s.SellerID=sl.SellerID and sl.sellingleadstatus='1' and ((c.IndustryID='$buyer_ind' and c.CategoryID=sl.CategoryID) or sp.KeyProducts like '%$buyer_keywords%' )";
}
else
{*/
$query1="select COUNT(*) as num FROM seller s, seller_profile sp,selling_leads sl,categories c where  s.SellerID=sp.SellerID and s.SellerID=sl.SellerID and sl.sellingleadstatus='1' and c.IndustryID='$buyer_ind' and sl.CategoryID=c.CategoryID";
//}

//echo "<br>".c.CategoryID;
//echo "<br>".sl.CategoryID;

echo $query1;
$result1=mysql_query($query1);
$num1=mysql_fetch_array($result1);
$num=$num1['num'];

echo "<br>NUM is $num";



if($num!=0)
{

/*
if($buyer_keywords!='')
{
$query="select * FROM seller s, seller_profile sp,selling_leads sl,categories c where  s.SellerID=sp.SellerID and s.SellerID=sl.SellerID and sl.sellingleadstatus='1' and ((c.IndustryID='$buyer_ind' and c.CategoryID=sl.CategoryID) or sp.KeyProducts like '%$buyer_keywords%' )";
}
else
{*/
$query="select *  FROM seller s, seller_profile sp,selling_leads sl,categories c where  s.SellerID=sp.SellerID and s.SellerID=sl.SellerID and sl.sellingleadstatus='1' and c.IndustryID='$buyer_ind' and sl.CategoryID=c.CategoryID";
//}
echo "<br>".$query;
$result=mysql_query($query);
$count_no=0;

while($row=mysql_fetch_array($result))
	{
if($i==$max_alert_page2)
break;
/*echo "categoryid ".$row['CategoryID'];
$q1="select COUNT(*) as cats from categories c1 where c1.CategoryID='$row[CategoryID]'";
$r1=mysql_query($q1);
$ar1=mysql_fetch_array($r1);
$cats=$ar1['cats'];
echo "cats: ".$cats;


$q2="select COUNT(*) as sells from selling_leads s1 where s1.CategoryID='$row[CategoryID]'";
$r2=mysql_query($q2);
$ar2=mysql_fetch_array($r2);
echo $sells=$ar2['sells'];
echo "sells: ".$sells;*/

echo "buyer_ind:".$buyer_ind."<br>";
echo $row['CategoryID']."<br>";
/*if(in_array($row['CategoryID'],$cats_all))
{*/




$count_no++;

$country=$row['Country'];
//echo "country is".$country;
$country ="<br>[".$country."]"."<br>";
//if(empty($country))
//$country="No country mentioned";
$sid=$row['SellerID'];
$sleadid=$row['SellingLeadID'];
$details_link="$root_path/supplier/sellinglead_details.php?SellingLeadID=$sleadid&SellerID=$sid";
$details=$row['BriefDescription'];
$subject=$row['Subject'];
$pic=$row['thumb1'];
$contact_seller="$root_path/supplier/contact_now.php?SellerID=$sid"; 
$photo ="$root_path/".$pic;


if(empty($pic))
{
$photo= "$root_path/images/no_photo.gif";
}
//echo "<br>i: ".$i;
if($i%2==0)
{
$row_add .= '<tr><td width=15%><a href='."\"$details_link\"".'><img src='."\"$photo\"".' border="0" width="100" height="100"></a></td><td width=35% valign="top"><a href='."\"$details_link\"".'>'."$subject".'</a><br>'."$details $country".'<br><a href='."\"$contact_seller\"".'>Contact</a></td>';
}
else
{
$row_add .= '<td width=15%><a href='."\"$details_link\"".'><img src='."\"$photo\"".' border="0" width="100" height="100"></a></td><td width=35% valign="top"><a href='."\"$details_link\"".'>'."$subject".'</a><br>'."$details $country".'<br><a href='."\"$contact_seller\"".'>Contact</a></td></tr>';
}
$i++;

//}


}
echo "found : ".$count_no;

$details_link="$root_path/selling_leads.php";

$send_page='
<html>

<body >

<p>Dear '."<b>$buyer_name".'</b>, <br>Here are the latest news of selling leads in BuyerXpo.com!</p><br>

  <table border=0 width=600 >
  <tr ><td><img src='."\"$root_path/images/alert_header.gif\"".'></td></tr>
  </table>
<table border=1 width=600 >
  <tr ><td><img src='."\"$root_path/images/logo1.jpg\"".'></td></tr>
  </table>
  
  <table border=1 width=600 cellpadding="10">
  <tr><td>New Products</td></tr>
  </table>
	<table border=1 width=600 cellpadding="10">
	<tr><td width=100% align=right><a href='."\"$details_link\"".'>View all</a></td></tr>
  </table>
  <table border=1 width=600 cellpadding="10">
';

$send_page.=$row_add;
$send_page.='</table>';
$send_page.='</body>';
$send_page.='</html>';

//echo $send_page;

$headers .= 'From: sales@buyerxpo.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";



$date=getdate();
//print_r($date);
$subject = 'BuyerXpo trade alert update '.$date['weekday'].", ".$date['month']." ".$date['mday'].", ".$date['year'];
$buyer_mail="shahid2k4@yahoo.com"."\r\n";
//echo $subject;
$sentmail = mail($buyer_mail, $subject, $send_page, $headers);
echo $headers;
echo $subject;
echo $buyer_mail;

echo $send_page;
$sentmail=1;

if($sentmail){
echo "Email has been sent to: ".$buyer_mail."<br>";
$total_sent++;
$succeed_mail .= "\r\n".$buyer_mail;
}
else {
echo "Cannot send email to ".$buyer_mail."<br>";
global $count_failed;
$count_failed++;
$failed_mail .= "\r\n".$buyer_mail;
}
}
}

/*echo "total mail send :".$total_send;
$logfile="alertlog_buyer.txt";
$fp=fopen($logfile,"a+");
$date=getdate();
$strdate = $date[month]." ".$date[mday].", ".$date[year]."  ".date(h).":".date(i).":".date(s);
if($count_failed==0)
$failed_mail="0";
$contents ="\r\n".$strdate.":  No. of failed alert to buyer:".$failed_mail."\r\n\r\n";
$contents .= "No. of succeeded alert to buyer: $total_sent \r\n \r\n\r\n";
fwrite($fp,$contents);
fclose($fp);*/

/**********************************/

?>






Please ask me If you need anything more.

I am really helpless coz last 8 days I m suffering with this Error.

Please Help me. I really need your help


Regards

Is This A Good Question/Topic? 0
  • +

Replies To: one mail function to multiple user with different categories

#2 TMKCodes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: one mail function to multiple user with different categories

Posted 17 June 2009 - 01:42 AM

Could be easier if the server providers would check the internal error log which gives more details what went wrong. http://www.checkupdo...tatus/E500.html

But the only thing i see wrong in headers is that the first header should not have the dot front of =

$headers = 'From: sales@buyerxpo.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";;



The header order might affect it too, because usually MIME is first then Content and additionals after them.

This post has been edited by TMKCodes: 17 June 2009 - 01:44 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1