hey y'all,
i have a form setup where i can plug in a bunch of html and then send it off as an email. it currently works for really simple HTML but as soon as i start plugging in my real style guide and images, it all goes fubar.
here's some code:
<?php
//above this point is for "test emails" to me and the team (view beofre sending to entire group)
elseif(isset($_POST['send_all']))
{
include "youwishyounew.php";
$subject = $_POST['subject'];
//just sending to a small group now for testing but this will ultimately be "everyone" opted in
// $get_all_emails = "SELECT * FROM customers WHERE newsletter = '1'";
$testing_emails = "SELECT * FROM customers WHERE customers_id = '1' OR customers_id ='2' OR customers_id ='6570'";
///testing purposes only:::
$all_email_query = mysql_query ($testing_emails);
//$all_email_query = mysql_query ($get_all_emails);
//test query
if (!$all_email_query)
{ echo mysql_error(); }
//create email list
$int = 0;
while ($results = mysql_fetch_array($all_email_query, MYSQL_ASSOC))
{ //first check to see if html or text email; then set to approriate type, $int is used to count # of times through loop (i.e. total entries)
$email_type = $results['customers_email_format'];
if ($email_type == "HTML")
{
$html_email .= $results['customers_email_address'];
$html_email .= ",";
}
if ($email_type == "TEXT")
{
$text_email .= $results['customers_email_address'];
$text_email .= ",";
}
$int++;
}//end of while
echo "html_email list: $html_email <br /> --- <br /> text_email list: $text_email <br />";
$html_email .= "james@doesntmatter.com";
$text_email .= "james@doesntmatter.com";
$total_sent = $int;
echo "total emails sent: $total_sent <br />";
$to="";
$from="sales@doesntmatter.com";
$html_message = $_POST['html_message'];
$text_message = $_POST['text_message'];
$html_message .= "<br /><p>To opt out from these emails, <a href=\"http://whateversiteiwant.com/index.php?main_page=unsubscribe\">click here </a></p>";
$text_message .= "<br /><p>To opt out from these emails, <a href=\"http://whateversiteiwant.com/index.php?main_page=unsubscribe\">click here </a></p>";
$headers = "FROM: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$html_headers .= $headers."\r\nBCC: $html_email\r\n";
$text_headers .= $headers."\r\nBCC: $text_email\r\n";
if (!mail($to, $subject, $html_message, $html_headers))
{ $admin_message = "didn't work; oops. <br />"; }
else {
mysql_close(); //close current connection to customer CMS, open connection to other db to update newsletter logs
include "database.inc.php";
$admin_message .= "email sent. hope you tested it first. ;-) <br />";
$insert_message = "INSERT INTO newsletters (html_message, text_message, total_sent, type) VALUES ('$html_message', '$text_message', '$total_sent', 'everyone')";
$insert_message_query = mysql_query($insert_message);
if(!$insert_query)
{ echo mysql_error(); }
}//end of else from mail ()
//email the text only bunch
if (!mail($to, $subject, $text_message, $text_headers))
{ $admin_message .="<br /> text version did not send<br />"; }
else
{$admin_message .="<br /> text version sent <br />"; }
//end of mail (text)
mysql_close (); //close any open connections
}//end of $_POST['send_all']
?>
i've attached a screenshot of the funky output (as viewed in google mail)
thx!!!