Mail received by Gmail but not others provider PHPMailer

Viewed 828

I'm implementing an auto email sender, Actually when I try to send my email automatically to a Gmail account, the mail is received, however when i try to send the same email to another mail domain (ex. @bouygues-construction.com), the PHP script say the email has been send but nothing is received... I'm using ionos (1&1) server mail :

    $data = file_get_contents("php://input");
    $dataAsJson = json_decode($data);
    $mail = new PHPMailer(true);
    try{
      $mail->IsSMTP();
      $mail->Mailer = "mail";
      $mail->SMTPAuth = true;
      $mail->Host = "smtp.ionos.fr";
      $mail->Port = 587; //465;
      $mail->SMTPDebug = 2;
      $mail->SMTPSecure = 'tls';
      $mail->Username = "******";
      $mail->Password = "******";
      $mail->Sender = "tpings@mydomain.fr";
      $mail->From = "tpings@mydomain.fr";
      $mail->AddAddress($dataAsJson->Email,$dataAsJson->Nom." ".$dataAsJson->Prenom);
      $mail->Subject = "Licence";
      $mail->FromName = "TPINGS Service";

      $mail->AddReplyTo('exemple@exemple.com', 'Contact TPINGS' );

      if($dataAsJson->English == true){
        $msg = "myMsg";
        $mail->AddAttachment("./uploads/Installation_EN.pdf");
      }else{
        $msg = "my_FR_msg";
        $mail->AddAttachment("./uploads/Installation_FR.pdf");
      }


      $mail->MsgHTML($msg);
      if(!$mail->Send()) {
          http_response_code(500);
          echo 'Erreur : ' . $mail->ErrorInfo;
        } else {
          http_response_code(200);
        }
    }catch(Exception $e){
      echo "Erreur mail : ".$mail->ErrorInfo;
    }

Sidenote: my spam folder is empty.

1 Answers

You've got some confusion in here - because you're setting Mailer after calling isSMTP, it means you're not using SMTP at all, and none of your SMTP settings will be used. Remove that line and try again and you should see SMTP debug output, and probably have more success. Your current code uses mail(), so any useful debug output will be in your local mail servers's log files.

It would only be affected by your own DNS if you were sending directly to the recipient's server. When you send through your ISP, it's their DNS that would be used.

Related