Jump to content

Trouble with how content displays after being sent through mail()


aebstract

Recommended Posts

Here is my mail script, runs on a cron job once a week.

 

<?php
set_time_limit(0);


mysql_connect("localhost","***","***") or die(mysql_error());
mysql_select_db("**_*_*");


$i = 1;
while ($i != 0){

$myquery = mysql_query("SELECT * FROM mailer ORDER BY RAND() LIMIT 1") or DIE(mysql_error());

while($r=mysql_fetch_array($myquery))
{
$id=$r["id"];
$flyer=$r["flyer"];
$date=$r["date"];
$used=$r["used"];
}

if ($used == 0) {
$i = 0;
    mysql_query("UPDATE mailer SET used='1' WHERE id=$id LIMIT 1") or DIE(mysql_error());
}

}


include "../eq$flyer.php";

$content = str_replace('class="contacttd"', 'bgcolor="c0c0c0" cellpadding="5"', $content);
$content = str_replace('class="contacttd2"', 'bgcolor="dddddd" cellpadding="5"', $content);
$content = str_replace('<h2>', '<h2 style=italic .5em Georgia, Times, serif;>', $content);


$message = "<html><head></head><body>$content</body></html>";
$fromaddress = 'admin@berryequipment.net';
$emailsubject = 'Berry Plumbing & Equipment - Product Information';





$emails = array("lots of emails");
$emailaddress = array_unique($emails);


$i = count($emailaddress);
$z = 0;


if ($i != 0){

while ($i != $z){

mail($emailaddress[$z], $emailsubject, $message, "From: " .$fromaddress. "\nX-Mailer: PHP 4.x");
$z++;

}

}







?>

 

Problem is, this is the email that I received:

 

<html><head></head><body></body></html>

 

I thought it was all correct so that it would put the content in to the email but I must have messed something up.

Link to comment
Share on other sites

You need to set some html headers. This...

 

mail($emailaddress[$z], $emailsubject, $message, "From: " .$fromaddress. "\nX-Mailer: PHP 4.x");

 

ought be replaced by...

 

$headers  = "From: $fromaddress\r\n"; 
$headers .= "Content-type: text/html\r\n";
mail($emailaddress[$z], $emailsubject, $message, $headers);

Link to comment
Share on other sites

I'm not sure if this is what's causing it, but try putting quotes around the style:

<h2 style="italic .5em Georgia, Times, serif;">

 

Even if the style wasn't right, it would still display the text/information without styling.

 

 

try changing $content =  to $content .= for the second two values...

 

I'm running a str_replace on my entire $content variable and replacing parts of it, not adding to it so the .= would have no working effect towards fixing the problem.

 

 

That leaves us with thorpe, I tossed your code in and it works ;) Thanks a bunch man.

 

 

 

 

edit: did they remove the topic solved feature?!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.