Sending mail via php does not work

-4

I'm using the same script I've used on other sites but it looks like this site is not sending emails.

If I send an email through the virtual control panel min the email is received in outlook in spam but in gmail it does not even arrive.

What should I do?

       <?php


    $subject = "example";
    $from ='[email protected]';
    $to ='<[email protected]>';
    $bcc = null; // Esconder endereços de e-mails.
    $cc = null; // Qualquer destinatário pode ver os endereços de e-mail especificados nos campos To e Cc.
    $message = "<!DOCTYPE html>
    <html>
    <head>
    <style>
    table {
        width:100%;
    }
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }
    th, td {
        padding: 5px;
        text-align: left;
    }
    table#t01 tr:nth-child(even) {
        background-color: #eee;
    }
    table#t01 tr:nth-child(odd) {
       background-color:#fff;
    }
    table#t01 th    {
        background-color: black;
        color: white;
    }
    </style>
    </head>
    <body>


    <table id='t01'>
      <tr>
        <th>Lisguagens uteis</th>
        <th>Sites</th>
        <th>Prioridade</th> 
      </tr>
      <tr>
        <td>HTML</td>
        <td>http://www.w3schools.com/</td>
        <td>1</td>  
      </tr>
      <tr>
        <td>CSS</td>
        <td>http://www.w3schools.com/</td>
        <td>2</td>  
      </tr>
      <tr>
        <td>JAVASCRIPT</td>
        <td>https://codecademy.com/learn/javascript</td>
        <td>3</td>  
      </tr>
      <tr>
        <td>PHP</td>
        <td>https://external.codecademy.com/learn/php</td>
        <td>4</td>  
      </tr>
    </table>
    <table id='t01'>
      <tr>
      <th>Nota:</th>
      </tr>
      <tr>
      <th>text exemple</th>
      </tr>
    </body>
    </html>";

    $headers = sprintf( 'Date: %s%s', date( "D, d M Y H:i:s O" ), PHP_EOL );
    $headers .= sprintf( 'Return-Path: %s%s', $from, PHP_EOL );
    $headers .= sprintf( 'To: %s%s', $to, PHP_EOL );
    $headers .= sprintf( 'Cc: %s%s', $cc, PHP_EOL );
    $headers .= sprintf( 'Bcc: %s%s', $bcc, PHP_EOL );
    $headers .= sprintf( 'From: %s%s', $from, PHP_EOL );
    $headers .= sprintf( 'Reply-To: %s%s', $from, PHP_EOL );
    $headers .= sprintf( 'Message-ID: <%s@%s>%s', md5( uniqid( rand( ), true ) ), $_SERVER[ 'HTTP_HOST' ], PHP_EOL );
    $headers .= sprintf( 'X-Priority: %d%s', 3, PHP_EOL );
    $headers .= sprintf( 'X-Mailer: PHP/%s%s', phpversion( ), PHP_EOL );
    $headers .= sprintf( 'Disposition-Notification-To: %s%s', $from, PHP_EOL );
    $headers .= sprintf( 'MIME-Version: 1.0%s', PHP_EOL );
    $headers .= sprintf( 'Content-Transfer-Encoding: 8bit%s', PHP_EOL );
    $headers .= sprintf( 'Content-Type: text/html; charset="iso-8859-1"%s', PHP_EOL );

    mail(null, $subject, $message, $headers);







    echo("enviado");
?>
    
asked by anonymous 07.02.2016 / 17:19

2 answers

0

Try:

<?php
$subject = "example"; //Assunto
$from ='[email protected]'; //Email de quem está enviando
$to ='[email protected]'; //Email de quem vai receber

$message = "<!DOCTYPE html>
    <html>
    <head>
    <style>
    table {
        width:100%;
    }
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }
    th, td {
        padding: 5px;
        text-align: left;
    }
    table#t01 tr:nth-child(even) {
        background-color: #eee;
    }
    table#t01 tr:nth-child(odd) {
       background-color:#fff;
    }
    table#t01 th    {
        background-color: black;
        color: white;
    }
    </style>
    </head>
    <body>


    <table id='t01'>
      <tr>
        <th>Lisguagens uteis</th>
        <th>Sites</th>
        <th>Prioridade</th> 
      </tr>
      <tr>
        <td>HTML</td>
        <td>http://www.w3schools.com/</td>
        <td>1</td>  
      </tr>
      <tr>
        <td>CSS</td>
        <td>http://www.w3schools.com/</td>
        <td>2</td>  
      </tr>
      <tr>
        <td>JAVASCRIPT</td>
        <td>https://codecademy.com/learn/javascript</td>
        <td>3</td>  
      </tr>
      <tr>
        <td>PHP</td>
        <td>https://external.codecademy.com/learn/php</td>
        <td>4</td>  
      </tr>
    </table>
    <table id='t01'>
      <tr>
      <th>Nota:</th>
      </tr>
      <tr>
      <th>text exemple</th>
      </tr>
    </body>
    </html>";

$headers = "MIME-Version: 1.1\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: ".$from."\r\n"; // remetente
$headers .= "Return-Path: $from\r\n"; // return-path

mail($to, $subject, $message, $headers, "-r".$from);
?>
    
07.02.2016 / 18:13
2

Hello, you must pass another parameter, the "sender", in this fifth parameter should be placed some email from your company or domain for example: [email protected] as it is in the PHP Manual:

<?php mail($to, $subject, $message, $headers, "[email protected]"); ?>

NOTE: The PHP manual explains why using -f

  

"Currently my hosting service is on Godaddy. When attempting to use   the mail function without the fifth parameter containing "-f", my   message headers would not work. "

In a free translation:

"My host is Godaddy.When I try to use the mail function without the fifth parameter with -f my emails do not work"

link

Without this fifth domain, it will send with a "strange" email that google, for example, considers malicious.

Make sure you are testing out of localhost.

    
07.02.2016 / 18:13