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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have built a web utility which se

Status
Not open for further replies.

buzzt

Programmer
Joined
Oct 17, 2002
Messages
171
Location
CA
I have built a web utility which send me an email as a reminder a few days before an event occurs. The problem is that if 3 emails are sent, the 3rd email will have the From email address in the header 3 times. How do I avoid this? Better still, how would I have just 1 email sent containing all the events that are coming up (rather than sending 1 for each event). The mail code is below:


for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
$first = $row['first_name'];
$last = $row['last_name'];
$type = $row['type'];
$bd = $row['date'];

$toaddress = &quot;main email address&quot;;
$subject = &quot;Your Events Reminder&quot;;
$mailcontent = &quot;Here is important event coming up in the next few days that you might not want to forget.\n\nName: &quot; . $first . &quot; &quot; . $last . &quot;\n\n&quot; . &quot;Date: &quot; . $bd . &quot;\n\n&quot; . &quot;Event: &quot; . $type;

$headers .= &quot;MIME-Version: 1.0\r\n&quot;;
$headers .= &quot;Content-type: text/plain; charset=iso-8859-1\r\n&quot;;
$headers .= &quot;From: \r\n&quot;;
$headers .= &quot;Cc: 2nd email address\n&quot;;

mail($toaddress, $subject, $mailcontent, $headers);
}
 
You'll probably find on closer inspection that all your headers are duplicated.

Change this line:

$headers .= &quot;MIME-Version: 1.0\r\n&quot;;

To read:

$headers = &quot;MIME-Version: 1.0\r\n&quot;;

This will, instead of concatenating more and more headers on each iteration of the for-loop, clear out the headers and start anew on each iteration.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Thanks a bunch. I still would like to find a way to send just 1 email out with all the events though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top