0

I try to test my code:

<?php

  use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\Exception;

  require_once __DIR__ . '/../PHPMailer/src/Exception.php';
  require_once __DIR__ . '/../PHPMailer/src/PHPMailer.php';
  require_once __DIR__ . '/../PHPMailer/src/SMTP.php';

        $mail = new PHPMailer(); // create a new object
        $mail->IsSMTP(); // enable SMTP
        $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
        $mail->SMTPAuth = true; // authentication enabled
        $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 587;
        $mail->IsHTML(true);
        $mail->Username = "----------@gmail.com";
        $mail->Password = "************";
        $mail->SetFrom("--------@gmail.com");
        $mail->Subject = "Test";
        $mail->Body = "hello";
        $mail->AddAddress("-----------@gmail.com");
        if(!$mail->Send()) {
          header("Location: login.php"); // ---------------- EXECUTES ------------- \\
          exit();
       } else {
          header("Location: index.php");
          exit();
       }
?>

For some reason I can't figure out, it fails (because I'm getting re-directed to login.php). I've tried to debug it with the latest ifs conditions..

  • @Dilek but if it executes it means failure.. – Qwert Trewq Jan 23 '20 at 19:41
  • woops sorry I didnt see this `!` remove that redirect and see if php giving you an error, `$mail->SMTPDebug = 1;` this should give you error. –  Jan 23 '20 at 19:41
  • @Dilek it doesn't show any errors – Qwert Trewq Jan 23 '20 at 19:51
  • 1
    it should! see documentation Enabling debug output https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output you need to show something to get help turn `$mail->SMTPDebug = 1;` to 2 –  Jan 23 '20 at 19:55

0 Answers0