E-mail falls into spam box PHP using HTML layout [duplicate]

1

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

I do not know what to do to avoid falling as spam.

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

In case the code is very simple, I submit a form HTML and get it by PHP.

The host used to send is: link

I do not want a guarantee that the email will never fall into the spam box, but rather the reason 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 respond.

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

The question is simple. Why in this code do emails fall as spam? What do I need to change in the code so I do not fall as spam? The problem of falling as spam, could 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>";
?>
    
asked by anonymous 21.05.2015 / 15:48

4 answers

2

Spam filtering systems are implemented by the recipients' email providers, and each provider can do it differently. The exact criteria for classifying an email as spam or not are usually sneaky, just so that spammers do not learn to tease them. In addition, these criteria change over time whether because of manual or automatic updates 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 is HTML formatted.
  • The email contains links to external sites, especially if they are known to be links to promotional content.
  • The email contains large images.
  • Email contains externally hosted images.
  • 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 commonly used for propagandistic purposes or fraud.
  • The recipient's real name is not mentioned in the email.
  • The email contains a large list of recipients, especially if these recipients were not previously known.
  • Many emails received from this sender have fallen into email accounts that have not been or have not been used for a long time.
  • The emails from this sender have already been reported as spam by some users.
  • The email contains an executable file as an attachment.
  • Answers sent to the sender's email have no e-mail box response or similar.
  • The email does not have a link to unsubscribe or has been determined that this link does not work properly.
  • The recipient has not received any e-mail from the sender in advance, especially registration confirmations.
  • Many other criteria ...

Much of the work of the anti-spam filter is in the words it contains in the email. Expressions such as "you've won a million dollars," "increase your penis," "get thinner now," "super promotion," "check out our offers," "find out what's the secret," " ten people "," make more money "," see photos of the party "," buy viagra ", etc., cause your email to fall into spam. In addition, anti-spam filters use artificial intelligence algorithms to learn new expressions like these automatically as they analyze incoming and outgoing emails.

And finally, your goal is to send email marketing, and a good many of the spam filters were designed exactly to pick up these emails, and the fact that they got 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 requested by the user, so let's focus on these categories:

  
  • The email does not have a link to unsubscribe or has been determined that this link does not work properly.
  •   
  • The recipient has not received any e-mail from the sender in advance, especially registration confirmations.
  •   

So if your site sent a confirmation email beforehand and your email has a link to the registration cancellation and your system respects the cancellation, your chances of falling on the anti-spam much less.

    
21.05.2015 / 16:18
2

Philip, use PHP Mailer: link It has some features that you can use, authentication. This may prevent you from falling into the Spam box.

Download the files for your project. Do not be scared with so many files. You will only use what is in the Code Requirement.

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';
}
    
21.05.2015 / 15:55
2

Who does the spam control is the server / client of the email recipient, you can solve it in case you can configure these email accounts, if you can configure the server or the email account.

Now that your email does not fall into the third-party spam box you can not control it.

    
21.05.2015 / 15:55
0

If you have very complex HTML content, google will spam that content. In the case the problem is not in PHP but in the 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 it does, change the code or change the layout.

I changed the

$arquivo = $_FILES['arquivo'];

by:

$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 you only have to change your CSS so that it stays as an email marketing layout. Manage images and links.

In case I could not make it work with any e-mail marketing layout I picked up on the internet. But I found that the problem is in HTML, too much content, too much CSS, etc.

    
21.05.2015 / 19:12