PhPmailer is not working, but there are no errors

Hi everyone,

I´m using PhPmailer to send my mails from the website. It´s my first site so i don´t know that much about hosting with Infinityfree. I think i made everything right with it, but it´s not working. There are no errormessages so i`m a bit surprised. I´m using Gmail and i´ve already searched for the solution in the other topics, but i got no result.
Thanks for your help!

<?php
use src\PHPMailer;
use src\SMTP;
use src\Exception;

require 'vendor/autoload.php';


    $mail = new PHPMailer();
    try {
    $mail->isSMTP();                                       
    $mail->Host       = 'smtp.gmail.com';          
    $mail->SMTPAuth   = true;                                
    $mail->Username   = '[email protected]';                    
    $mail->Password   = 'mypass';                               
    $mail->SMTPSecure = "ssl";         
    $mail->Port       = 465;
                        
    $mail->setFrom("[email protected]", "topic");
    $mail->addAddress($Email);
                        
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body    = $message;
    $mail->AltBody = $message;
    $mail->send();
                        
    echo 'sent';
    } catch (Exception $e) {
    console_log("not sent" . $mail->ErrorInfo); }

?>

This?

1 Like

I´ve already tried, it´s not working at all. :frowning:

Can you provide a URL???

For sure:
Schuelerhelfenschuelern.rf.gd

Im from germany, so it is written in german. the design for the phone is not finished yet. But for the pc or tablet its finished. Id like to use phpmailer to reset the password.

Can you let me know the location of the “submit.php” file?
Thanks

I made a functions.php file for all functions. There is a folder, in which its located. So:
Htdocs/login-files/functions.php

Which submit.php file?

Nevermind that, I was thinking you were using a template.

Could you provide the full code that is used in both the page and submitting of the form? Make sure to sensor passwords.

Thanks

No, i typed everything myself… :slight_smile: For sure i can do that:

function emailsenden(){

if($_SERVER['REQUEST_METHOD'] == 'POST'){
$Email = cleanHtml($_POST['reset-email']);


$subject = "Passwort zur&uuml;cksetzen";
$message = "http://localhost/GitHub/Schueler-helfen-Schuelern/reset.php?email=$Email";
                    
                
$mail = new PHPMailer();
try {
$mail->isSMTP();                                       
$mail->Host       = 'smtp.gmail.com';          
$mail->SMTPAuth   = true;                                
$mail->Username   = '[email protected]';                    
$mail->Password   = 'mypass';                               
$mail->SMTPSecure = "ssl";         
$mail->Port       = 465;
                                        
$mail->setFrom("[email protected]", "topic");
$mail->addAddress($Email);
                                        
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body    = $message;
$mail->AltBody = $message;
$mail->send();
                                        
echo 'sent';
} catch (Exception $e) {
console_log("not sent" . $mail->ErrorInfo); }    
}
return;
}

and here the html form:

<div class="container container-klein">
   <div class="left">
   <?php emailsenden();?>
       <form method="POST">
           <div class="header">
               <h2 class="header-login">Setze dein Passwort zur&uuml;ck</h2>
           </div>
       <div class="form">
           <input type="email" name="reset-email" id="inputEmail" class="form-field" placeholder="Email Addresse">
       </form>
  <a class="login-link" href="Nachhilfelehrer-login.php">Login</a>
  <button type="submit" name="reset-btn" class="login-btn">Mail senden</button>
</div>
</div>
<div class="right"></div>
</body>

Im sorry, but i dont use comments…

Commenting is not an issue for me, one thing I love about myself is that I can understand HTML and PHP pretty well without comments (One cannot say the same for CSS though, I use comments galore in that.)

A few things to check:

  1. The PHP file is in the same directory as the HTML file and is called exactly “Nachhilfelehrer-login.php” (Note that filenames are case sensitive)

  2. “Less Secure Apps” is enabled in your Google Account Settings

  3. You are using an App Password (Not the password you use to sign in to Google), and have 2Fa enabled.

not working at all… :frowning:

What’s this console_log function? Did you verify that this function can correctly produce output? If it didn’t, that would explain why you don’t see anything.

Could you perhaps try using PHP functions directly (like echo, var_dump(), etc.) to try to generate some output?

Also, like Greenreader said, not using 2FA when using Gmail also tends to break. Gmail is quite protective like that.

1 Like

Nothing

The more information you provide, the better we can help you. If you just say “not working” and “nothing”, there is “nothing” we can do for you.

2 Likes

then im sorry, but it displays nothing. There are no additional information i can give you. But Thanks!

That’s very odd because your PHPMailer code is configured to either say sent if it succeeded or not sent if it did not succeed. If you don’t see either of those things, something else than just a PHPMailer error is occurring.

1 Like

First: thanks for your help! When I use the function, every html code after it is no longer executed. In the console was this error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)

So did i integrate the files wrong? ive already searched for this error, but i found nothing with php.
Thanks

Actually, HTTP error 500 means your PHP code crashed. See below.

2 Likes