Send email in HTML format with background image and text on top of image

Asked

Viewed 1,933 times

0

I’m making a website where the customer registers his email and when registering he will automatically receive an email with a newsletter.

To send this email I am using Phpmailer

<?php

require 'PHPMailer/PHPMailerAutoload.php';

$email = $_POST['email'];


$Mailer = new PHPMailer();

//Define que será usado SMTP
$Mailer->IsSMTP();

//Enviar e-mail em HTML
$Mailer->isHTML(true);

//Aceitar carasteres especiais
$Mailer->Charset = 'UTF-8';

//Configurações
$Mailer->SMTPAuth = true;
$Mailer->SMTPSecure = 'tls';

//nome do servidor
$Mailer->Host = 'servidor.com.br';
//Porta de saida de e-mail
$Mailer->Port = 30;

//Dados do e-mail de saida - autenticação
$Mailer->Username = '[email protected]';
$Mailer->Password = 'MinhaSenha';

//E-mail remetente (deve ser o mesmo de quem fez a autenticação)
$Mailer->From = '[email protected]';

//Nome do Remetente
$Mailer->FromName = utf8_decode('Agência');

//Assunto da mensagem
$Mailer->Subject = utf8_decode('Seja bem-vindo');

//Corpo da Mensagem
$Mailer->Body = utf8_decode('<div style="background-color:#e6f8fe;">
  <!--[if gte mso 9]>
  <v:background xmlns:v="urn:schemas-microsoft-com:vml" fill="t">
    <v:fill type="tile" src="http://agencia306.com.br/blog-306/img/como-aproximar/1.jpg" color="#e6f8fe"/>
  </v:background>
  <![endif]-->
  <table height="100%" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td valign="top" align="left" background="http://agencia306.com.br/blog-306/img/como-aproximar/1.jpg">    <h1>Em fase de construção </h1>   </td>
    </tr>
  </table>
</div>');

//Corpo da mensagem em texto
$Mailer->AltBody = 'conteudo do E-mail em texto';

//Destinatario
$Mailer->AddAddress($email);

if($Mailer->Send()){
    echo "<script>alert('E-mail enviado com sucesso');history.back();</script>";
}else{
    echo "<script>alert('Erro no envio do e-mail: " . $Mailer->ErrorInfo . " ');history.back();</script>";
}

?>

The code is working smoothly, the email arrives smoothly for the person who signs up. But I’m having two problems:

1° Problem: Sending this way, I test in my Yahoo email, the email goes without problem. But the main goal is to send a background image and text on top of that image is not working. It’s just going text.

2° Problem: Going to Span. I researched about and read that using Phpmailer this wasn’t going to happen. But it’s going to Span.

2 answers

2


First thing you need to know to create email marketing is that the patterns are the oldest of HTML, from the time when CSS was not used to format things. So to make a text with background image you should put the text inside a table, and use the attribute background tag table.

<table width="100%" border="0" cellspacing="0" cellpadding="20" background="http://www.seudominio.com.br/img/background_image.png">
<tr>
    <td>
        <p>Content on a pretty background image.</p>
    </td>
</tr>
</table>

Even to change fonts you will need to use the tag <font>, for margins you will need to use the padding or Spacing of the table itself. Email marketing is boring to assemble, but this is how we should do.

So often people create as an image and place the text in an image alt attribute.

To not get caught as spam you should make sure some things. For example:

  • Text cannot detect keywords by anti spam, such as: "buy", "promotion" or similar words.
  • The domain must have SPF and DKIM configured correctly authorizing the sending server
  • You must have some text in your email, not just images
  • You must send each email individually, without thousands of addresses in copy
  • The sending server must be reliable and the sending tools as well, such as: Amazon SES, Mailchimp, Madmimi
  • You also need to have a lot of faith :)
  • Hello Carlos, thank you very much. I’m having a lot of doubts about the background URL. Because I put it this way you said it. I used the html background. But it’s still not working. I saw in your example background="background_image.png" you only used the image name. No need to enter its location??

  • Yes, it needs to be the full url and host the image somewhere. In the case of tools like Mailchimp, you can already climb through the tool itself and it hosts this image for you.

  • The best part of the answer: "You also need to have a lot of faith :)" :p

  • kkkkkkkkkk but it’s true...spam is a boring business and varies a lot from server to server that is receiving the email. Turns and moves has user complaining that did not receive.

  • Do you have any tutorial to use this Mailchimp, please? Pq just put the full url not working.

  • 1

    With this Mailchimp I add in my codes?? Pq site is being made in pure code, no platform like wordpress.

  • @Wess youtube has a lot of videos explaining how to move Mailchimp and Mailchimp itself is very intuitive. It has an area to upload images and such. Like you’re trying to?

  • 1

    Thank you very much Carlos. I actually tried in other ways here without using Mailchimp. But thank you very much, what you went through helped me a lot. I tried the method you passed using the html background, but even calling the whole url, when the email arrives, the background image does not appear.

  • 1

    But in question, from appearing in spam I did the processes you went through and thank God, I believe that now this quiet. Thank you very much

Show 4 more comments

0

Good morning, by limitation of several email readers, you can not use backgroud, I’ve broken my head to make it work however there is no way you guarantee, gmail works, but not in outlook, and in several phone readers does not work.

About spam, it goes much more from the reputation of your email server and your email address. But communication strategies in email can sometimes solve your problem, worth investing some time in these email questions.

  • I suggest you remove your answer and add it as a comment, since it does not provide a solution to the question to which you refer.

Browser other questions tagged

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