The problem does not happen only in emails, so please no phpmailer suggestions as I'm having trouble submitting the html-formatted text that was typed in textarea even on my own page.
If I put it in php:
$html = "<p style='color:red;'>Mensagem:</p>".$_POST['mensagem'];
Then the word "Message" when it arrives in the email arrives in red, but what is inside the post (which would be a textarea) "message" comes only text, if I put it inside:
<p style='color:red;'>exemplo</p>
Only the sample word without a red color will appear when the email arrives.
By my tests, it is not only in the email that it does not arrive formatted the html, if I send on the screen of my page what was typed in textarea, also does not format the html that was typed there .
Basically this is what is happening in my code, everything inside the textarea is not turning into HTML in email, but if I type the html code in my php, it will probably be some form of treat the missing textarea post.
Follow my code almost completely down (without the form):
function enviar($metodo,$op) {
if ($metodo=="Hospedagem") {
$emailremetente = $_POST['emailremetente'];
$array_domain=array("@oi.com.br","@gmail.com");
foreach ($array_domain as $elemento) {
$emailsender = str_replace("$elemento","@127.0.0.1",$emailremetente);
}
$nomeremetente = $_POST['nomeremetente'];
$assunto = $_POST['assunto'];
$array_destinatario = array();
$array_destinatario = explode("\n",trim($_POST['emaildestinatario']));
$message = opcao("$op");
imprime_headers($array_destinatario,$nomeremetente,$emailsender,$emailremetente,$assunto);
foreach($array_destinatario as $elemento) {
$headers = headers($emailsender,$nomeremetente,$assunto);
if (mail($elemento, $assunto, $message, implode("\r\n", $headers), "-r". $emailsender)){
emailEnviado($elemento,$metodo,$nomeremetente);
}else {
emailFalhou($elemento,$metodo,$nomeremetente);
}
}
?><div class="imprime_msgSent">Terminou! Veja a mensagem que foi enviada:</div><?php
echo "<div style='border:1px solid gray;padding:15px;background-color:rgba(0,0,0,0.4);margin-bottom:5px;'>$message</div>";
echo "<div style='border:1px solid gray;padding:15px;background-color:rgba(255,255,255,0.5);margin-bottom:5px;color:black;'>".htmlentities($message)."</div>";
}
}
function opcao($var) {
if ($var=="template") {
changeTemplate($_POST['nomeremetente'],$_POST['telefone'],$_POST['cnpj'],$_POST['site'],$_POST['assunto']);
include("inc/htmlT.php");
$message = $htmlT;
}
else if ($var=="textarea") {
$_SESSION["mensagemHTML"] = $_POST["mensagem"];
$message = "
<div style='padding:5px;border:1px solid pink;color:yellow;background-color:blue;'>HtMl PeRsOnAlIzAdO Do <strong>bArUlHo</strong></div>
<hr/>
{$_SESSION['mensagemHTML']}
";
}
return $message;
}
function headers($emailsender,$nomeremetente,$assunto) {
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: {$emailsender}";
$headers[] = "Reply-To: ".str_replace(" ","_",$nomeremetente)."<{$emailremetente}>";
$headers[] = "Subject: {$assunto}";
return $headers;
}
E-mail screen in form with html code to exit YELLOW:
Screenaftersent,youcanseethatitdidnotgooutyellow,andintheemailitalsodoesnotreceiveanyyellowformattingbecauseofthestylecoloryellow.
Here below is the image of receiving in thunderbird (it stays the same in gmail, etc.)