E-mail an html code typed in the textarea by php

Asked

Viewed 724 times

1

The problem not only happens in emails, so please no phpmailer suggestions, because I’m having trouble presenting the html formatted text that was typed in the textarea even on my own page.

If I put 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 (that would be a textarea) "message" arrives only text, if I put inside:

<p style='color:red;'>exemplo</p>

Only the example word with no red color will appear when the email arrives.

By my tests, it is not only in the email that it does not arrive formatted html, if I have it displayed on the screen of my page what was typed in the textarea, also it does not format the html that was typed there.

Basically this is what is occurring in my code, everything that is within the textarea is not turning into html in email, but if I type the html code in my php, it will, probably is some way to treat the textarea post that is missing.

Follow my code almost whole 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;
}

Email screen in form with html code to exit YELLOW:

ENVIANDO

After submitted screen, you may notice that it has not left the yellow color, and in the email also does not receive any yellow color formatting because of Yellow color style.

ENVIADO

Down here is the image of the receipt on Thunderbird (it looks the same on gmail, etc)

RECEBIDO NO EMAIL

  • What is the content of $_POST["message"] after sending the post form (print with var_dump($_POST["message"])?

  • You’re displaying it within a span?

  • vmartins, if I give vardump it looks like this: string(51) " insert html text here ;"

  • Khaosdoctor: No, I don’t put in a span, why should I?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.