How to format php mail?

Asked

Viewed 1,115 times

6

I’m having trouble inserting formatting into the code. Whenever I send, I receive the email the formatting tags as <html> <body>, <strong>, <b>, <p>, etc....

Follow code with html formatting that does not work.

    $to = $your_email;
    $subject="Pedido $numeroPedido de $name";
    $from = $your_email;
    $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

    $html ="
    <p><b>$name</b> enviou um arquivo mensagem:</p>
    <p><b>Número do Pedido:</b> $numeroPedido</p>   
    <p><b>Endereço:</b> $endereco</p>
    <p><b>Endereço:</b> $estado</p>     
    <p><b>Cidade:</b> $cidade</p>
    <p><b>Telefone:</b> $telefone
    <p><b>Celular:</b> $celular</p>                         
    <p><b>Email:</b> $visitor_email</p>
    <p><b>Informações Adicionais:</b></p>
    <p>$user_message</p>
    <p><b>IP:</b> $ip</p>
    ";  

    $headers = "From: $from \r\n";
    $headers .= "Reply-To: $visitor_email \r\n";

    if (mail($to, $subject, $html, $headers)) {

Thanks in advance =)

1 answer

5


Add a header, set which will be the type of email, text/Plain(default) or text/html. There are other more practical options for this, such as phpmailer or swiftMailer.

$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$headers .= 'Content-type: text/html;' . "\r\n";

Browser other questions tagged

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