Email falls into PHP spam box using HTML layout

Asked

Viewed 2,818 times

0

I registered three emails in my database, but when I send the email it falls into the spam box.

I don’t know what I should do not to fall as spam.

In case the content of the email is an email marketing html. (containing photos and content written in html).

In case the code is very simple, I send a form the HTML and caught by PHP.

The host used to send is: http://hostbase.com/

I don’t want a guarantee that the email will never fall into the spam box, but why it is falling into the spam box.

This is not a question of opinion, but of experience, so if you have no experience of why this is happening, please do not answer.

I believe I was not clear on the question, so I decided to edit it.

The question is simple. Why do emails fall as spam in this code? What do I need to change in the code in order not to fall as spam? The problem of falling as spam may be the HTML layout?

<?php
include_once "conexao.php";

$email = $_POST['email'];
$nome = $_POST['nome'];
$assunto = $_POST['assunto'];
$arquivo = $_FILES['arquivo'];
$arquivo = file_get_contents($_FILES['arquivo']['tmp_name']);

$sql = "SELECT `id`, `email` FROM `mailmarketing` ";
$query = $mysqli->query($sql);
echo '<table><tr><td>E-mail: </td></tr>';
while ($dados = $query->fetch_array()) {
$destino = $dados['email'];
// É necessário indicar que o formato do e-mail é html
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$nome.' <'.$email.'>';
//$headers .= "Bcc: $EmailPadrao\r\n";
 echo '<tr><td>' . $dados['E-mail'] . '</td><td>';
$enviaremail = mail($destino, $assunto, $arquivo, $headers, "-f$email");
if($enviaremail){
    echo "<b>E-mail enviado com sucesso!</b>";
//echo " <meta http-equiv='refresh' content='1;URL=index.php'>";
} else {echo "<b>erro ao enviar o e-mail!</b></br>";}
echo "</td></tr>";
}//echo 'Registros encontrados: ' . $query->num_rows;
echo "</table>";
?>
  • 3

    Felipe, I don’t think you understand the point of fellow @Sneepsninja. The point is, it doesn’t matter if it’s the user or the filtering system that sends your email to the spam box. You can’t guarantee on your side that the message is never marked as SPAM. It is not your/your system’s assignment, simple as that. What you can do is follow best practices to try not to characterize your email as spam. Your two questions are somewhat confusing in the sense that they do not ask for such practices, but rather a way of guaranteeing something for which there are no guarantees.

  • Felipe, an interesting tip is to use SMTP or a service like Mandrill for submissions, and configure the dkim and Spf of the domain. This brutally changes the chances of an email being considered spam.

  • Using SMTP is very interesting, our colleague Diego Souza sent a code from github to send emails using SMTP (Phpmailer) Thank you very much to everyone who helped me, but I believe that the question has become much more complex than I imagined. I just wanted to make sure that e-mail didn’t fall into the spam box. But now I believe I have gained some more knowledge that I can put into practice for an email marketing. But the focus wasn’t email marketing, I just wanted to know why the email was falling into the spam box and how could I fix it.

  • 2

    This question is being discussed in the Meta: http://meta.pt.stackoverflow.com/questions/3791/post-markedas duplicated by%C3%A9m-n%C3%A3o-necess%C3%A1riamente-similar

4 answers

2

Felipe, use PHP Mailer: https://github.com/PHPMailer/PHPMailer There are some features you can use, authentication. This can make you avoid falling into the spam box.

Download the files for your project. Don’t be frightened by so many files. You will only use what is in the Code Require.

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.seusite.com.br';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = '*****';                           // SMTP password
$mail->SMTPSecure = '';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->addAddress('[email protected]');               // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
  • It sounds interesting, I’ll test it here and see if it solves my problem. But I still can not understand why the email sent falls into the spam box. I’ve been thinking of two possibilities, either it’s the server or it’s my php code.

  • @Felipejorge, may be due to several factors already explained by other colleagues. The specific diagnosis may be difficult to find.

  • @Sneepsninja. Yes, I agree with you. But I believe this is not the case. Email is falling into spam deliberately and not because the user has put a rule so that every email from a given domain falls into the SPAM box. Obviously there is no way to control the incoming server of all servers.

  • PHP Mailer uses SMTP authentication, plus I wanted some code to decrease the chance of spam. Using SMTP helps in much the end result. The problem was in the HTML layout. About the diagnosis being hard to find, it’s not hard to find because in a small line of codes and sending to just 3 emails is not a very big challenge.

2

Who controls spam is the server/client of the email recipient, you can resolve if in case you can set up these email accounts, if you can set up the server or email account.

Now so your email doesn’t fall into the third-party spam box you can’t control.

2


Spam filtering systems are implemented by recipients' email providers, and each provider can do it in a different way. The exact criteria for classifying an email as spam or not usually are confidential, just so spammers don’t learn to circumvent it. In addition, these criteria change over time either because of manual or automatic upgrades based on artificial intelligence and machine learning.

But, there are some things that clearly make your emails more likely to be detected as spam:

  • The email has HTML format.
  • The email contains links to external websites, especially if they are links known to contain promotional content.
  • The e-mail contains large images.
  • The email contains images hosted externally.
  • Many similar emails were received from the same sender.
  • Many similar emails were received from multiple email addresses in a short time.
  • The email contains text with words and sentences normally used for propaganda or fraud purposes.
  • The real name of the Registry is not mentioned in the email.
  • The email contains a large list of recipients, especially if these recipients did not previously know each other.
  • Many emails received from this sender have fallen into missing or unused email accounts for a long time.
  • Emails from this sender have already been reported as spam by some users.
  • The email contains an executable file as attachment.
  • Replies sent to sender’s email has reply from non-existent or similar email box.
  • Email does not have a link to unsubscribe or it has been determined that this link does not work properly.
  • The recipient did not receive any e-mail from the sender previously, in particular registration confirmations.
  • Many other criteria...

Much of the work of the anti-spam filter is in the words it contains in the email. Expressions like "you won a million dollars", "enlarge your penis", "lose weight", "super-promotion", "check out our offers", "find out what the secret is", "send this email to ten people", "earn more money", "see the photos of the party", "buy viagra"etc., make your email fall into spam. In addition, anti-spam filters use artificial intelligence algorithms to learn new expressions like these automatically as they analyze emails sent and received.

And finally, their goal is to send email marketing, and a lot of the spam filters are designed to precisely pick up these emails, and the fact that they took yours, is a sign that they worked for the purpose for which they were designed.

One way to get away from these filters is when the email is actually prompted by the user, and then we’ll focus on these categories:

  • Email does not have a link to unsubscribe or it has been determined that this link does not work properly.
  • The recipient did not receive any e-mail from the sender previously, in particular registration confirmations.

So, if your site has sent a previous registration confirmation email and your email has a link to cancel the registration and your system respects the cancellation, your chances of falling into anti-spam are greatly reduced.

0

If you have very complex HTML content, google will spam that content. In this case the problem is not in PHP but in html layout. In case before sending to multiple people, it would be interesting to test and see if your HTML layout does not fall into the spam box. If you fall, change the code or change the layout.

I switched the

$arquivo = $_FILES['arquivo'];

for:

$arquivo = "<html>
<meta charset='UTF-8' /> 
<table width='510'  bgcolor='#fff'>
<tr>
    <td width='500'><b>Nome: </b>$nome</td>
</tr>
<tr>
    <td width='320'><b>E-mail: </b>$email</td>
</tr>   
</table>
</html>";

Now all you need to do is change the CSS so it looks like an email marketing layout. Ease up on the images and links.

In case I couldn’t make it work with any email marketing layout picked up on the internet. But I found that the problem is in HTML, too much content, too much CSS, etc.

Browser other questions tagged

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