Send email with PHP containing HTML [closed]

1

I'm trying desperately to send an email via PHP, as per the code below. But the code breaks when I enter HTML, example:

$mensagem = "<html> (...) </html>";

I'll need a whole page in there! I've tried it too:

   // Abre o template...
   $corpoDoEmail = file_get_contents(index.txt');

   //E troca as variáveis
   $corpoDoEmail = str_replace( '%NOME%', $nome,       $corpoDoEmail );

But it does not work, it does not bring any data.

<?php

$para = "[email protected]";
$nome = $_POST['nome'];
$assunto = "Ebah! Temos um novo usuário!";
$mensagem = "<strong>Nome:  </strong>".$nome;
$mensagem .= "<br><br>O usuário: ".$_POST['nome'];
$mensagem .= " quer receber nosso e-mail de Bem Vindo!";

QUERO O CONTEÚDO HTML AQUI

$headers =  "Content-Type:text/html; charset=UTF-8\n";   
$headers .= "From:  Golleo<[email protected]>\n";
$headers .= "X-Sender:  <[email protected]>\n"; 
$headers .= "X-Mailer: PHP  v".phpversion()."\n";   
$headers .= "X-IP: ".$_SERVER['REMOTE_ADDR']."\n";   
$headers .= "Return-Path:  <[email protected]>\n";
$headers .= "MIME-Version: 1.0\n";

mail($para, $assunto, $mensagem, 
$headers);

?>
    
asked by anonymous 24.02.2016 / 18:50

2 answers

0

Try switching to this Header

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Note: Change the entire Header.

I noticed an error in your code posted above, forgot to put a quote.

// Abre o template...
$corpoDoEmail = file_get_contents(index.txt');

change to

// Abre o template...
$corpoDoEmail = file_get_contents('index.txt');
    
24.02.2016 / 19:36
0

Good afternoon, you can use the phpmailer library, the use is easy and very simplified:

require_once("../phpmailer/class.phpmailer.php");
$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'seunome';
$email->Subject   = 'assunto';
$email->msgHTML('<html>Mensagem HTML</html}>');
$email->AddAddress('[email protected]');

$email->send();

This example is sending HTML messages.

PHPMailer

    
25.02.2016 / 20:37