Reputation: 47
I'm trying to send an email in PHP that is written with CKEditor, or HTML. When the email is sent the HTML code appears in the email, I know it but the Headers already tried putting immense and none works.
Below is my code to send the email.
function mail_users($titulo, $conteudo){
$query = mysql_query("SELECT `Email`, `Nome` FROM `utilizadores` WHERE `Newsletter` = 'Ativada'");
while (($row = mysql_fetch_assoc($query)) !== false){
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
email($row['Email'], $titulo, "Olá " . $row['Nome'] . ",\n\n" . $conteudo, $header);
}
}
Upvotes: 2
Views: 103
Reputation: 9635
try this
function mail_users($titulo, $conteudo)
{
$header = "MIME-Version: 1.0\r\n";
$header .= "From: [email protected]";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$query = mysql_query("SELECT `Email`, `Nome` FROM `utilizadores` WHERE `Newsletter` = 'Ativada'");
while($row = mysql_fetch_assoc($query))
{
mail($row['Email'], $titulo, "Olá " . $row['Nome'] . ",\n\n" . $conteudo, $header);
}
}
Upvotes: 0
Reputation: 81
Try this i think you just have to make header blank each time it enter into the loop.
and check
@mail($email, $subject, $message, $headers);
the last line has all the values accordingly .
function mail_users($titulo, $conteudo){
$query = mysql_query("SELECT `Email`, `Nome` FROM `utilizadores` WHERE `Newsletter` ='Ativada'");
while (($row = mysql_fetch_assoc($query)) !== false){
$header='';
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
@mail($row['Email'], $titulo, "Olá" . $row['Nome'] . ",\n\n" . $conteudo, $header);
}
}
Upvotes: 0
Reputation: 68476
You should do this way..
mail()
instead of email()
[Unless you have written a wrapper for the same]function mail_users($titulo, $conteudo){
$query = mysql_query("SELECT `Email`, `Nome` FROM `utilizadores` WHERE `Newsletter` = 'Ativada'");
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
while (($row = mysql_fetch_assoc($query)) !== false){
mail($row['Email'], $titulo, "Olá " . $row['Nome'] . ",\n\n" . $conteudo, $header);
}
}
Upvotes: 1