Mail () function does not send the email

0

I've now transferred a site where I'm working for a remote server, and I noticed now that mail does not reach my gmail inbox. I used a very simple method of code but it does not work, although it appears written "" Your email was sent successfully! ":

    <?php
header('Content-type: text/html; charset=UTF-8');
$name = $_POST['name'];
$email = $_POST['email'];
$carga_type = $_POST['carga_type'];
$weight = $_POST['weight'];
$local = $_POST['local'];
$destiny = $_POST['destiny'];
$date = $_POST['date'];
$company = $_POST['company'];
$tele = $_POST['tele'];
$vol_number = $_POST['vol_number'];
$volume = $_POST['volume'];
$size = $_POST['size'];
$notes = $_POST['notes'];

$to = "[email protected]";
$subject = "Nova messagem";
$message = "De: ".$name."<br>
            Email: ".$email."<br>
            Tipo de carga: ".$carga_type."<br>
            Peso: ".$weight."<br>
            Local: ".$local."<br>
            Destino: ".$destiny."<br>
            Data: ".$date."<br>
            empresa: ".$company."<br>
            Telefone: ".$tele."<br>
            Número de volumes: ".$vol_number."<br>
            Volume: ".$volume."<br>
            Medidas C x L x A: ".$size."<br>
            Notas: ".$notes."<br><br>";

echo ($message);
if (($name == "") || ($carga_type == "") || ($date == "") || ($local == "") || ($tele == "") || ($vol_number==""))
{
echo 'Preencha todos os os campos mínimos necessários (Nome, Tipo de carga, Data, Local e Numero de telefone.)';
}
else
{
    mail($to, $subject, $message);
    echo "O seu email foi enviado com sucesso! ";
}
?>
    
asked by anonymous 31.03.2014 / 19:11

5 answers

2

Try this (keeping in mind that the SMTP service is working correctly on the server):

    $name = $_POST['name'];
    $email = $_POST['email'];
    $carga_type = $_POST['carga_type'];
    $weight = $_POST['weight'];
    $local = $_POST['local'];
    $destiny = $_POST['destiny'];
    $date = $_POST['date'];
    $company = $_POST['company'];
    $tele = $_POST['tele'];
    $vol_number = $_POST['vol_number'];
    $volume = $_POST['volume'];
    $size = $_POST['size'];
    $notes = $_POST['notes'];

    $to = "[email protected]";
    $subject = "Nova messagem";
    $message = "De: ".$name."<br>
                Email: ".$email."<br>
                Tipo de carga: ".$carga_type."<br>
                Peso: ".$weight."<br>
                Local: ".$local."<br>
                Destino: ".$destiny."<br>
                Data: ".$date."<br>
                empresa: ".$company."<br>
                Telefone: ".$tele."<br>
                Número de volumes: ".$vol_number."<br>
                Volume: ".$volume."<br>
                Medidas C x L x A: ".$size."<br>
                Notas: ".$notes."<br><br>";


            $headers = "From: $from \r\n".

                       "MIME-Version: 1.0" . "\r\n" .

                       "Content-type: text/plain; charset=UTF-8" . "\r\n"; 

            if(mail($to,$subject,$message,$headers)){
echo "email enviado com sucesso";
}
    
01.04.2014 / 12:20
1

This has happened to me and I added a header and it worked, in my case. Here's an example:

$headers = 'From: Titulo da aplicacao <[email protected]>'."\r\n" .
        'Reply-To: [email protected] '. "\r\n" .
        'X-Mailer: MyFunction/' . phpversion().
        'MIME-Version: 1.0' . "\n".
        'Content-type: text/html; charset=UTF-8' . "\r\n";

mail($email,$titulo,$HTML,$headers);
    
01.04.2014 / 12:32
1

ex:

 if( mail($to,$subject,$message,$headers, '-r'.$sender) ){
  echo "enviado";
 }

where $ sender should be the email that is sending the message, it is an additional configuration beyond the headers required by postfix.

    
01.04.2014 / 20:23
-1

Some hosting servers require authentication to send emails programmatically. And no error is being displayed, because the way you wrote your code, regardless of the result of the mail () function you have an echo with the phrase "Your email was sent successfully!". Consider using the PHPMailer class, it greatly facilitates these settings for sending e-mail, including authenticated SMTP.

    
31.03.2014 / 20:07
-2

I've placed the script in a .rar file in Google Drive for you to download.

I always use this script on my sites that has outgoing server verification and verification (SMTP) to prevent your email from crashing or falling into the spam box. Most of the time it works without problems, just configure the data in the file send_email.php do not forget this!

Do not forget to send the PHPMAILER folder to the server together.

  

DOWNLOAD HERE

     

* To download, just go to the File tab > > Download or CTRL + S

    
31.03.2014 / 20:52