Jump to content

[SOLVED] Mass Email w/graphics works but.....


echromes

Recommended Posts

I took two php mail() tools and put them together. One will send an email address in your mysql table and loop through sending each one until the end. [that works] The other lets you send graphics and text [that works]. Now that they are together I can send one at a time no problem when I comment out  // $headers .= "Bcc: $email\n"; but then only get 1 email and the others in the mysql table are skipped. If I don’t comment out that line it sends a blank email to each address in the mysql table. I need to Bcc so I don’t share out all my customers email accounts. This is not spam I am sending. They are my customers that want to receive a small news letter each month. Below is that code and any help would be great. [email protected]

----------------------------------------------------------------

<?php

//MySQL database connection information

$dbhost = 'host';

$dbuser = 'user';

$dbpass = 'pass';

$dbname = 'dbname';

$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql');

mysql_select_db($dbname);

 

$headers = "From: me<[email protected]>";

$to = '[email protected]';

$subject = 'get this to work';

$html ="If you can not see the graphics below, click here to view it in a new window<br>

To ensure proper delivery, please add [email protected] to your contact list.<br><br><br>

<img src='http://www.me.com/myimage.jpg'<br />

_________________________________________________________________<br>

If you wish to UNSUBSCRIBE from receiving any future emails click here.<br><br>

Copyright © me, LLC 2009<br>

<br />";

//the below is your own plain text message (all the $message(x))

$message0 = 'If you can not see the graphics below, click here to view it in a new window';

$message1 = '';

$message2 = 'me - http://www.me.com';

$message3 = '';

$message4 = '';

$message5 = '';

$message6 = '';

$message7 = '';

$message8 = '';

$message9 = '';

$message10 = '';

$message11 = '' ;

$message12 = '';

$message12 = '';

// Generate a boundary string that is unique

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment

$headers .= "\nMIME-Version: 1.0\n" .

"Content-Type: multipart/alternative;\n" .

" boundary=\"{$mime_boundary}\"";

$message = "--{$mime_boundary}\n" .

"Content-Type: text/html; charset=\"iso-8859-1\"\n" .

"Content-Transfer-Encoding: 7bit\n\n" .

"<font face=Arial>" .

$html."\r\n";

$message .= "--{$mime_boundary}\n" .

"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .

"Content-Transfer-Encoding: 7bit\n\n" .

$message0 . "\n\n" .

$message1 . "\n\n" .

$message2 . "\n\n" .

$message3 . "\n\n" .

$message4 . "\n\n" .

$message5 . "\n\n" .

$message6 . "\n\n" .

$message7 . "\n\n" .

$message8 . "\n\n" .

$message9 . "\n" .

$message10 . "\n" .

$message11 . "\n" .

$message12 . "\n\n";

 

// Lookup email addresses from mysql table

$query = "SELECT email from accounts";

$result = mysql_query($query) or die("Error in query: $query. ".mysql_error());

 

while ($row = mysql_fetch_assoc($result))

{

    $email = $row['email'];

    echo "$email<br />";

    // $headers .= "Bcc: $email\n";    //  <- - THIS IS THE LINE

}

 

// Send the message

mail($to, $subject, $message, $headers);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/155437-solved-mass-email-wgraphics-works-but/
Share on other sites

I got - Warning: mail(): Bad parameters to mail() function, mail not sent.

 

It did add a space infront of the first "Bcc......  but still didn't work.

 

here is the echo $headers

 

From: me MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="==Multipart_Boundary_xf7dcc42093a584a8d135878764e77f62x"Bcc: [email protected] Bcc: [email protected] Bcc: [email protected]

hmmm... maybe instead of adding the newline before the bcc code stuff (because since it loops it will add 2 new lines between all but the first one, which probably messed up the function to begin with)

 

take the following line

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=\"{$mime_boundary}\"";

and change it to this

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=\"{$mime_boundary}\"\n";

 

really, besides the newline that MIGHT be missing, I have no clue. It looks like it should work to me. Hope that helps.. sorry if it doesn't

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.