Email with PHP does not reach the recipient. Failure with the server?

-1

The php mail () function returns true or false . I get true but the email does not reach the destination and I think it's because of the server configuration. I use a Linux Debian server.

Code:

$para .= '[email protected]';
$título = 'Recordatorio de cumpleaños para Agosto';
$mensaje = 'Hola';
$cabeceras = 'MIME-Version: 1.0' . "\r\n";
$cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$cabeceras .= 'To: Mary , Kelly ' . "\r\n";
$cabeceras .= 'From: Recordatorio ' . "\r\n";
$cabeceras .= 'Cc: [email protected]' . "\r\n";
$cabeceras .= 'Bcc: [email protected]' . "\r\n";
mail($para, $título, $mensaje, $cabeceras);
    
asked by Deivid Chavez Mamani 13.03.2018 в 21:44
source

1 answer

0

Hello, you can use PHPMailer and your Gmail account to send emails in this way. Saludes

<?php
//Load 
require_once('PHPMailer/PHPMailerAutoload.php'); 

$mail = new PHPMailer(true); 
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$mail->SMTPDebug = 2; 
$mail->IsSMTP();
$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;// TCP port to connect to
$mail->CharSet = 'UTF-8';
$mail->Username ='[email protected]'; //tu gmail
$mail->Password = '31542'; //tu password
//Agregar destinatario
$mail->setFrom('[email protected]', 'Mary , Kelly');
$mail->AddAddress('[email protected]');//A quien mandar email
$mail->SMTPKeepAlive = true;  
$mail->Mailer = "smtp"; 

    //Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Recordatorio de cumpleaños para Agosto';
$mail->Body    = 'Hola</b>';


if(!$mail->send()) {
  echo 'Error al enviar email';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Mail enviado correctamente';
}
    
answered by 16.03.2018 в 07:27