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

PHP Mail dumping email addresses in message body 1

Status
Not open for further replies.

nwruiz

Programmer
Jun 22, 2005
60
US
Hello,

I currently have implemented a mailing list on my website. However, there is a small bug that causes the email addresses to get dumped into the body of the email and messes up my HTML formatting. I was wondering if someone could help me troubleshoot this problem.

Here is the snippet of PHP code that is responsible for sending the email:

Code:
// Store email addresses to Bcc:
    $bcc = $emailAddress[0];
    for($i = 1; $i < count($emailAddress); $i++)
    {
      $bcc .= ", " . $emailAddress[$i];
    }
    
    // Set up message
    $to = "noreply@dealmerchant.net, " . $bcc;
    $from = "From: noreply@dealmerchant.net";
    $headers = $from . "\r\n";
    $headers .= "To: noreply@dealmerchant.net, " . "\r\n";
    $headers .= "cc: \r\n";
    $headers .= "Bcc: " . $bcc . "\r\n";
    $headers .= "Subject: DealMerchant.net deals for today" . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    
    print("<p><u>Bcc List</u><br>\n");
    print($bcc . "</p>\n");
    
    $sent = mail($to, 'DealMerchant.net deals for today', $htmlFormat, $headers);
    if(!$sent)
      die("Message failed to send.");
    else
      print("<p>Email " . $emails . " sent.");

The variables that store my html output are formatted correctly. The problem is that my messages looks like this:

Code:
, *********@hotmail.com

, ****************@hotmail.com

, *********@hotmail.com

, *******@hotmail.com

, ***********@hotmail.com

, *************@hotmail.com

, *********@hotmail.com


Subject: DealMerchant.net deals for today

MIME-Version: 1.0

Content-type: text/html; charset=iso-8859-1



<html>
<body>
<div align='center'>
<h3>Today's Deals at <a href='[URL unfurl="true"]http://www.dealmerchant.net'>DealMerchant.net:</a></h3>(http://www.dealmerchant.net)[/URL]
</div>
<p><font color='gray'>Amazon.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#120'>Ceiva[/URL] Advanced Digital Photo Receiver with Silver Frame only $99.99! </a></p>

<p><font color='gray'>Amazon.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#121'>10kt.[/URL] White Gold, 1/10 ct. tw. Diamond "Right Hand" Ring only $99.99!</a></p>

<p><font color='gray'>Compgeeks.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#122'>Virtual[/URL] Reality Head-Mounted LCD Display $117.50!</a></p>

<p><font color='gray'>Compgeeks.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#123'>Lexmark[/URL] Z515 USB 4800x1200 Color Inkjet Printer $29.00!</a></p>

<p><font color='gray'>Compgeeks.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#124'>Nokia[/URL] 3300 GSM MP3/FM Radio Music Phone (Metallic Blue) $79.99!</a></p>

<p><font color='gray'>Compgeeks.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#125'>Shuttle[/URL] AV49PN VIA PT800 Socket 478 ATX MB w/Snd, SATA $34.00!</a></p>

<p><font color='gray'>Compgeeks.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#126'>RCA[/URL] Lyra RD2780 20GB MP3/WMA Audio/Video Jukebox $234!</a></p>

<p><font color='gray'>Compgeeks.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#127'>Audiovox[/URL] 38 Channel GMRS 2-Way Radios (2-Pack) $19.99!</a></p>

<p><font color='gray'>Overstock.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#128'>Premium[/URL] Memory Foam 4-inch Mattress Topper (All Sizes) $169.99!</a></p>

<p><font color='gray'>BestBuy.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#129'>Western[/URL] Digital 120.0GB Internal Hard Drive $34!</a></p>

<p><font color='gray'>BestBuy.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#130'>Western[/URL] Digital 120.0GB External USB 2.0 Hard Drive $79!</a></p>

<p><font color='gray'>BestBuy.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#131'>$10[/URL] off for every $100 you spend!</a></p>

<p><font color='gray'>CircuitCity.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#132'>Linksys[/URL] WRT54G Wireless 802.11g router $39 with free shipping!</a></p>

<p><font color='gray'>Dell.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#133'>Up[/URL] to 30% off Dell LCD Monitors!</a></p>

<p><font color='gray'>Dell.com</font><br>
<a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/#134'>Up[/URL] to $60 off your Dell Electronics and Accessories order!</a></p>

<hr>
<p>You have received this email because you or someone you know added your email address to the DealMerchant.net mailing list. If you do not wish to receive any daily updates, visit <a href='[URL unfurl="true"]http://www.dealmerchant.net/BETA2/unsubscribe.php'>http://www.dealmerchant.net/BETA2/unsubscribe.php</a></p>[/URL]
</body></html>

Not only is the formatting completely wrong, the email addresses are not hidden from the viewer. Any advice would be greatly appreciated.

Nick Ruiz
CO-OP Intern, PPL Electric Utilities
Webmaster, DealMerchant.net
 
My advise always:
Use the PHPMailer class available at sourceforge.net
It has all bells and whistles and using it will prevent any such problems as yours.

I notice that you append the bcc addresses with the $to variable. That will expose all addresses. The idea of a Bcc: header is to send the mail to one recipient ($to) and have blind carbon copies delivered to the addresses listed in the Bcc header. Your headers 'To:' and the $to in the call to the mail() function are different.
 
Is there a need that sourceforge.net can't meet? PHPMailer works beautifully. Thanks.

Nick Ruiz
CO-OP Intern, PPL Electric Utilities
Webmaster, DealMerchant.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top