PHP Mail | Form emails do not arrive to my mail server

0

I would like to know if there is any way to get mail sent from a form to an email from my company.

I tried with my gmail mail and it works correctly. But I send from another email and they do not arrive ...

My form:

<form method="post" action="php/enviarmails/enviarContactos.php" >
    <div class="fields">
        <div class="field half" >
            <label for="nombre" >Nombre</label>
            <input type="text" name="nombre" id="nombre" />
        </div>
        <div class="field half">
            <label for="email" >Correo Electronico</label>
            <input type="text" name="email" id="email" />
        </div>
        <div class="field half">
            <label for="celular" >Celular</label>
            <input type="text" name="celular" id="celular" />
        </div>
        <div class="field half">
            <label for="empresa" style="color:#46A1BE">Empresa</label>
            <input type="text" name="empresa" id="empresa" />
        </div>
        <div class="field">
            <label for="mensaje" style="color:#46A1BE">Escriba un mensaje</label>
            <textarea name="mensaje" id="mensaje" rows="6" ></textarea>
        </div>
    </div>
    <ul class="actions">
        <li><input type="submit" value="Enviar Mensaje" class="primary" /></li>
        <li><input type="reset" value="Limpiar"  /></li>
    </ul>
</form>

My php code:

<?php  
    $texto_mail=$_POST["mensaje"];
    $nombre=$_POST["nombre"];
    $email=$_POST["email"];
    $celular=$_POST["celular"];
    $empresa=$_POST["empresa"];
    $destinatario="[email protected]";
    $asunto="Escribieron en contactos CYGNUS";
    $headers="MIME-Version: 1.0\r\n";
    $headers.="Content-type: text/html; charset=iso-8859-1\r\n";
    $headers.="From: Escribieron en la Pagina < [email protected] >\r\n";
    $exito=mail($destinatario,$asunto,"Correo Electronico " . $email . "<br>" . "Nombre: " . $nombre . "<br>Celular: ". $celular . "<br> Empresa: " . $emrpesa .  "<br> Comentario del mensaje: " . $texto_mail ,$headers);

    if ($exito) {
        header("location: ../../enviadoContactos.html");
    } else {
        echo "Ha ocurrido un error";
    }
?>

The truth is that I do not know if it is my hosting or the mail server of the company the reason why they do not arrive.

If you have some experience about this, I would appreciate it.

    
asked by Juanse Portillo 13.08.2018 в 17:19
source

1 answer

1

I have had this problem in the past with some domains and it is because the bad function of PHP originally does not meet the minimum score to not be considered spam, in some cases the message is not even sent to the spam tray but which is discarded directly.

I recommend using PHPMailer (Available at link )

It is the best option, just create an email account in your hosting (for example [email protected]) this will serve to configure your PHPMailer and being an email sent by an existing protocol and mail sure that if will reach all recipients (or at least Spam).

Basic use.

<?php

require 'PHPMailer-master/PHPMailerAutoload.php';
require 'PHPMailer-master/class.smtp.php';


$mail = new PHPMailer;
$mail->CharSet = "UTF-8";
$mail->isSMTP();      
$mail->SMTPDebug = 0; //ACTIVALO SI QUIERES VER EL DEBIG
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

$mail->Host = $config_notificaciones_defecto_host;  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = $config_notificaciones_defecto_username;                 // SMTP username
$mail->Password = $config_notificaciones_defecto_pasword;                           // SMTP password
$mail->SMTPSecure = $config_notificaciones_defecto_smtpsecure;                            // Enable TLS encryption, 'ssl' also accepted
$mail->Port = $config_notificaciones_defecto_puerto;    
$mail->setFrom($config_notificaciones_defecto_fromcorreo, $config_notificaciones_defecto_frondescripcion);
$mail->SMTPKeepAlive = true; // NO CERRAR LA CONEXION HASTA ENVIAR TODOS LOS CORREOS

$mail->Subject = "Bienvenido a MI WEB "; 
$mail->AltBody = 'SOY UN RESUMEN PARA CELULAR';

$mail->Body    ='<!doctype html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title> </title>
</head>
<body style="background: #e4e9f0;">
   SOY UN CORREO
</body>
</html>';

$paquien=$mail_bienvenido_destino;

    $mail->addAddress($paquien, $paquien);
    if (!$mail->send()) {
        echo "Mailer Error (" . str_replace("@", "&#64;", $paquien) . ') ' . $mail->ErrorInfo . '<br />';
        break; //Abandon sending
    }

    // LIMPIARMOS DIRECCION Y ADJUNTOS PARA CONTINUAR
    $mail->clearAddresses();
    $mail->clearAttachments();

?>
    
answered by 14.08.2018 / 06:44
source