4
I am trying to send an email via PHP with HTML attributes, an email formatted with images and style="" or classes. I tried to use Phpmailer, but without success, so I resorted to the mail() function of PHP that meets my needs and sends the email without many problems, the only problem in itself is that the email is not authenticated and keeps falling into quarantine, Can I take any action to correct this?
Another problem, my main is that email does not send when I try to put tags as
<div style="text-align: center; margin: 0 auto;"></div>
and also when I try to add images with <img src='http://meusite.com.br/templates-email/cabecalho.jpg' alt='img' />
(only one example).
The point is:
- How to send HTML emails using the mail() function (including images in this email and Divs). ?
- How to solve the problem of the authenticity of emails (they live in quarantine).
ATTEMPT 1 (does not send).
//envia e-mail de confirmação
$email_remetente = "[email protected]";
$headers = "MIME-Version: 1.1\n";
$headers .= "Content-type: text/HTML; charset=utf-8\n";
$headers .= "From: $email_remetente\n"; // remetente
$headers .= "Return-Path: $email_remetente\n"; // return-path
$headers .= "Reply-To: $email_usuario\n"; // Endereço (devidamente validado) que o seu usuário informou no contato
$texto_mensagem = "<html><head><title>Blue Contract - Ative sua conta</title></head><body>";
$texto_mensagem .= "<div style=\'font: 14px Arial, Tahoma; text-align: center; margin: 0 auto;\'>";
$texto_mensagem .= "<img src='http://bluecontract.com.br/templates-email/cabecalho.jpg' alt='img' />";
$texto_mensagem .= "<h1>Ativação de conta - Blue Contract</h1>";
$texto_mensagem .= "<p>Através de nosso website, você efetuou um cadastro em ".$usuDataCadastro."</p>";
$texto_mensagem .= "<p>Agora, para finalizar seu cadastro é necessário confirmar sua conta.</p>";
$texto_mensagem .= "</div>";
$texto_mensagem .= "</body></html>";
$envio = mail(base64_decode($usuEmail), "Blue Contract - Ative sua conta", $texto_mensagem, $headers, "-f$email_remetente");
// Exibe uma mensagem de resultado
if ($envio) { } else { header("Location: ".URL."criar-conta?tk=".$usuToken."&eee#ve"); exit(); }
ATTEMPT 2
//envia e-mail de confirmação
$email_remetente = "[email protected]";
$headers = "MIME-Version: 1.1\n";
$headers .= "Content-type: text/HTML; charset=utf-8\n";
$headers .= "From: $email_remetente\n"; // remetente
$headers .= "Return-Path: $email_remetente\n"; // return-path
$headers .= "Reply-To: $email_usuario\n"; // Endereço (devidamente validado) que o seu usuário informou no contato
$texto_mensagem = "<html>
<head>
<title>Blue Contract - Ative sua conta</title>
</head>
<body>
<div style=\'margin: 40px auto; margin-left: auto; margin-right: auto; text-align: center;\'>
<img src=\'http://bluecontract.com.br/templates-email/cabecalho.jpg\' width=\'100%\'/>
</div>
E-mail: <b>[email protected]</b>
</body></html>";
$envio = mail(base64_decode($usuEmail), "Blue Contract - Ative sua conta", $texto_mensagem, $headers, "-f$email_remetente");
// Exibe uma mensagem de resultado
if ($envio) { } else { header("Location: ".URL."criar-conta?tk=".$usuToken."&eee#ve"); exit(); }
I tried to do these two ways, both with the same image problem.
Remembering that the sending of email happens, then my problem is not that emails do not reach destination.
I like to use the swiftmailer. I find it simpler.
– gmsantos
I’ve heard of swiftmailer, but I’ve never had a contact with the code or even used it, I’ve analyzed the site now and it really seems to be very simple. Interesting tool also.
– Tiago Boeing