# PhPmailer is not working, but there are no errors

**URL:** <https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135>\
**Category:** Hosting Support\
**Created:** [August 18, 2021, 3:54pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135 "2021-08-18T15:54:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 18, 2021, 3:54pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/1 "2021-08-18T15:54:01Z")

</div>

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!

```auto
<?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 = 'mymail@gmail.com';                    
    $mail->Password = 'mypass';                               
    $mail->SMTPSecure = "ssl";         
    $mail->Port = 465;
                        
    $mail->setFrom("mymail@gmail.com", "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); }

?>

```

---

<div class="post-metadata">

**Author:** ![KangJL](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/kangjl/32/12130_2.png) [@KangJL](https://forum.infinityfree.com/u/KangJL)\
**Post date:** [August 18, 2021, 4:03pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/2 "2021-08-18T16:03:38Z")

</div>

This?

> [@"SMTP connect() failed" on InfinityFree but not on XAMPP Localhost](https://forum.infinityfree.com/t/smtp-connect-failed-on-infinityfree-but-not-on-xampp-localhost/49430/4):
>
> Try this. Ensure that “Less Secure Apps” is enabled in your Google Account Settings. Turn on 2Fa (Two Factor Authorization) on your Google account Generate an App Password for your account (It’s under “Privacy”) and use that instead of your real password. Apply the changes and upload to the server Clear your cache and cookies and let me know if it works.

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 18, 2021, 4:11pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/3 "2021-08-18T16:11:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [August 18, 2021, 5:58pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/4 "2021-08-18T17:58:33Z")

</div>

Can you provide a URL???

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 18, 2021, 6:11pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/5 "2021-08-18T18:11:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [August 18, 2021, 6:13pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/6 "2021-08-18T18:13:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 18, 2021, 7:05pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/7 "2021-08-18T19:05:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 18, 2021, 7:16pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/9 "2021-08-18T19:16:11Z")

</div>

Which submit.php file?

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [August 18, 2021, 7:18pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/10 "2021-08-18T19:18:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 18, 2021, 7:28pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/11 "2021-08-18T19:28:26Z")

</div>

No, i typed everything myself… 🙂 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 = 'mymail@gmail.com';                    
$mail->Password = 'mypass';                               
$mail->SMTPSecure = "ssl";         
$mail->Port = 465;
                                        
$mail->setFrom("mymail@gmail.com", "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>

```

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 18, 2021, 7:33pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/12 "2021-08-18T19:33:11Z")

</div>

Im sorry, but i dont use comments…

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [August 18, 2021, 8:57pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/13 "2021-08-18T20:57:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 19, 2021, 11:57am UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/14 "2021-08-19T11:57:33Z")

</div>

not working at all… ☹

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [August 19, 2021, 6:22pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/15 "2021-08-19T18:22:45Z")

</div>

> [@anon96796542](#):
>
> `console_log("not sent" . $mail->ErrorInfo); }`

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.

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 20, 2021, 11:53am UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/16 "2021-08-20T11:53:48Z")

</div>

Nothing

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [August 20, 2021, 12:20pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/17 "2021-08-20T12:20:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 20, 2021, 4:08pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/18 "2021-08-20T16:08:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)\
**Post date:** [August 20, 2021, 5:07pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/19 "2021-08-20T17:07:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon96796542](https://forum.infinityfree.com/letter_avatar/anon96796542/32/6_449c533f586939b6e5f246632a46421f.png) [@anon96796542](https://forum.infinityfree.com/u/anon96796542)\
**Post date:** [August 20, 2021, 9:37pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/20 "2021-08-20T21:37:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Greenreader9](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/greenreader9/32/22847_2.png) [@Greenreader9](https://forum.infinityfree.com/u/Greenreader9)\
**Post date:** [August 20, 2021, 11:01pm UTC](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135/21 "2021-08-20T23:01:37Z")

</div>

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

> [@Http error 500](https://forum.infinityfree.com/t/http-error-500/49352):
>
> When trying to access your website, you may see a page which returns the status code “500”. In Google Chrome, you’ll see a page with the error code HTTP ERROR 500. There are typically two reasons which can cause this error: The PHP code has crashed. The .htaccess file contains invalid rules. Here are some things you can try to debug and fix this. Fixing crashing PHP code A HTTP ERROR 500 simply tells you that the PHP code has crashed, but gives no information as to why it has crashed. Gett…

[Next page](https://forum.infinityfree.com/t/phpmailer-is-not-working-but-there-are-no-errors/50135.md?page=2)
