warning: mail () [function mail]: SMTP server response: 550.5.7.1 [email protected] ... Relaying denied. IP name possibly forged [191 ... 174] in line 100

0

I currently have an application that sends emails through phpmailer .

The problem is that it only sends emails that have the domain of my company.

When there is an email that is gmail domain, hotmail or another domain, it does not send and displays the following message:

 warning: mail() [function mail]: SMTP server response: 550.5.7.1 <[email protected]>... Relaying denied. IP name possibly forged [191...] in line 100

my 100 line contains:

 mail($destinatario,$asunto,$body);

The data I use from smtp is an email from my company.

I think it's a security configuration that I do not have, can someone help me?

   $sql = "select EMAIL1_CLI from planilla";      

                $rpt = mysqli_query($sub_db,$sql)or die(mysqli_error());
                //$asunto = 'Aviso de Deuda'; 

                $mail             = new PHPMailer(); // defaults to using php "mail()"
                $body             = "Este es un mensaje automatico...";


                $mail->From       = "[email protected]";
                $mail->FromName   = "Francisco Acevedo Diaz";



                $mail->AddAddress('[email protected]','Clientes'); //deb poner variable que traiga mail y nombre del cliente
                $mail->SetFrom('[email protected]', 'Depto. Cobranza');



                $asunto = $mail->Subject = 'Aviso de deuda en oriental Motors';


                $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
                $mail->MsgHTML($body);



                $mail->IsSMTP();
                $mail->Host = "mail.xx.cl";


                // optional
                // used only when SMTP requires authentication  
                $mail->SMTPAuth = true;
                $mail->Username = 'xx';
                $mail->Password = 'xx';


                while ($des = mysqli_fetch_array($rpt)) {
                    $destinatario = $des["EMAIL1_CLI"];
                    printf ($destinatario);

                    //$mail->AddAddress = $des['EMAIL1_CLI'];
                    //$mail->AddAddress("[email protected]");
                    mail($destinatario,$asunto,$body);

                }   

                    if(!$mail->Send()) {
                      echo "Mailer Error: " . $mail->ErrorInfo;
                      exit;
                    } else {
                      echo "Message sent!";
                    }
                }  

Edition 2 (send the emails to all, but send as 5 emails to each recipient):

   $sql = "select EMAIL1_CLI from planilla";      

                $rpt = mysqli_query($sub_db,$sql)or die(mysqli_error());


                $mail             = new PHPMailer(); // defaults to using php "mail()"
                $body             = "Este es un mensaje automatico...";


                $mail->From       = "[email protected]";
                $mail->FromName   = "Francisco Acevedo";




                $mail->SetFrom('[email protected]', 'Depto. Cobranza');



                $asunto = $mail->Subject = 'Aviso de deuda en oriental Motors';


                $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
                $mail->MsgHTML($body);



                $mail->IsSMTP();
                $mail->Host = "mail.xx.cl";



                $mail->SMTPAuth = true;
                $mail->Username = 'xx';
                $mail->Password = 'xx';


                while ($des = mysqli_fetch_array($rpt)) {
                    $destinatario = $des["EMAIL1_CLI"];

                    $mail->AddAddress($destinatario);

                    $mail->send();

                }   
    
asked by Francisco Acevedo 15.09.2018 в 19:01
source

3 answers

0

Finally I managed to find the solution, I had 2 problems:

1) The first: I was occupying 2 methods at the same time, one in php (function mail) ,  and at the same time the phpmailer library, that's why I had conflicts with the amounts of emails received and sent ...

2) The second: I had syntax problems in the code lines when using the While method.

Finally the solution was to re-configure phpmailer and disable (function mail)

In this way the correct syntax was as follows:

            $mail = new PHPMailer();

            // Activamos el servicio SMTP
            $mail->isSMTP();
            // Activamos / Desactivamos el "debug" de SMTP 
            // 0 = Apagado 
            // 1 = Mensaje de Cliente 
            // 2 = Mensaje de Cliente y Servidor 
            $mail->SMTPDebug = 2; 

            // Log del debug SMTP en formato HTML 
            $mail->Debugoutput = 'html'; 

            // Servidor SMTP (para este ejemplo utilizamos gmail) 
            $mail->Host = 'mail.xx.com'; 

            // Puerto SMTP 
            $mail->Port = 587; 

            // Tipo de encriptacion SSL ya no se utiliza se recomienda TSL 
            $mail->SMTPSecure = ''; 

            // Si necesitamos autentificarnos 
            $mail->SMTPAuth = true; 

            // Usuario del correo desde el cual queremos enviar, para Gmail recordar usar el usuario completo ([email protected]) 
            $mail->Username = "xx"; 

            // Contraseña 
            $mail->Password = "xx"; 

            // Conectamos a la base de datos 
            //$db = new mysqli('hostname', 'usuario', 'cotraseña', 'basededatos'); 

            if ($sub_db->connect_errno > 0) { 
                die('Imposible conectar [' . $sub_db->connect_error . ']'); 
            } 

            // Creamos la sentencias SQL 
            $result = $sub_db->query("SELECT * FROM planilla");

            // Iniciamos el "bucle" para enviar multiples correos. 

            while($row = $result->fetch_assoc()) { 
                //Añadimos la direccion de quien envia el corre, primero el correo, luego el nombre de quien lo envia. 


                $mail->setFrom('[email protected]', 'Depto. Cobranza'); 
                $mail->addAddress($row['EMAIL'], $row['NOMBRE']); 

                //La linea de asunto 
                $mail->Subject = 'Aviso de Deuda!'; 

                // La mejor forma de enviar un correo, es creando un HTML e insertandolo de la siguiente forma, PHPMailer permite insertar, imagenes, css, etc. (No se recomienda el uso de Javascript) 
                $body = "Estimado cliente ";
                $mail->MsgHTML($body);

                // Enviamos el Mensaje 
                $mail->send(); 

                // Borramos el destinatario, de esta forma nuestros clientes no ven los correos de las otras personas y parece que fuera un único correo para ellos. 
                $mail->ClearAddresses(); 
            } 

Thank you very much to those who supported the answers.

    
answered by 17.09.2018 / 22:50
source
1

You are using the mail function, which is internal to php, in the

statement
mail($destinatario,$asunto,$body)

with which you are not using phpmailer to make the shipment. In phpmailer it is sent with the function send (). To send with PHPMailer you should use;

$mail->send();

You can review the documentation at PHPMailer . You also have a simple example of how to send messages with PHPMailer.

    
answered by 15.09.2018 в 20:33
0

The error itself is related to the fact that an SMTP server is not recognizing you as an authorized user to send mails through it. This is an anti-spam protection. Some servers, like GMail, have quite high restrictions to avoid this. This permission is usually based on allowed IP addresses or a username / password login.

Some things to keep in mind: 1) From the server's point of view, for example; verify the reverse DNS address, verify that the IP address is not in a black list, etc. 2) From the point of view of the code: complete the field of the recipient with the name in addition to the email address, add a field "Reply To" (and that is valid), etc.

NOTE: Regarding the second point I see that you use "From" and "SetFrom" at the same time and different and that you did not define an "addReplyTo" field.

I hope this helps, greetings!

    
answered by 15.09.2018 в 21:55