# Using Php Mailer

**URL:** <https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985>\
**Category:** E-mails\
**Tags:** hébergement-web\
**Created:** [September 24, 2026, 1:06pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985 "2026-09-24T13:06:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Driver](https://community.ovhcloud.com/letter_avatar/driver/32/6_22734026db12803ebb3e059622ac3534.png) [@Driver](https://community.ovhcloud.com/u/Driver)\
**Post date:** [September 24, 2026, 1:06pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/1 "2026-09-24T13:06:28Z")

</div>

Hello

Given the constant problems with the mail function, I’m trying to use PHPMailer but I’m getting a 500 error.  
Here is the test script I’m using (almost identical to the one shown in the OVH documentation, without using Composer)

```
require 'src/PHPMailer.php';
require 'src/SMTP.php';
require 'src/Exception.php';

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

$mail = new PHPMailer(true);

try {
$mail->isSMTP();
$mail->Host = 'smtp.mail.ovh.net';
$mail->SMTPAuth = true;
$mail->Username = 'moi@mondomaine.com';
$mail->Password = 'mon mdp';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->setFrom('moi@mondomaine.com', 'Moi');
$mail->addReplyTo('moi@mondomaine.com' ,'moi');

$mail->addAddress('moi@free.fr', 'moi'); 

$mail->isHTML(true);
$mail->Subject = 'Test PHPMailer';
$mail->Body = 'Ceci est un email de test en <b> HTML </b>'; 
$mail->AltBody = 'Ceci est un email de test en texte brut.'; 

$mail->send();
echo 'Email envoyé !';

}
catch (Exception $e) {
echo "Erreur l'email n'a pas été envoyé: {$mail->ErrorInfo}";
}

```

My test.php file is set to chmod 755 in the PHPMailer directory.  
I assume I missed something, but I can’t see where.

---

<div class="post-metadata">

**Author:** ![sturpin](https://community.ovhcloud.com/user_avatar/community.ovhcloud.com/sturpin/32/30025_2.png) [@sturpin](https://community.ovhcloud.com/u/sturpin)\
**Post date:** [September 24, 2026, 1:57pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/2 "2026-09-24T13:57:25Z")

</div>

Hi @Driver

Check if the error might be in the file paths:

```php
require __DIR__. '/src/PHPMailer.php';
require __DIR__. '/src/SMTP.php';
require __DIR__. '/src/Exception.php';

```

If your `src` folder is not in the same directory as `test.php`, adjust the path accordingly.

If the 500 error persists, add these lines at the beginning of your script so PHP shows the actual error instead of a blank page.

```php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

```

I think your 500 error is not due to your PHPMailer configuration nor the test.php file itself, but because the `require` paths are relative and can't find the library files.

Let us know, cheers.  
Sergio Turpín

---

<div class="post-metadata">

**Author:** ![Driver](https://community.ovhcloud.com/letter_avatar/driver/32/6_22734026db12803ebb3e059622ac3534.png) [@Driver](https://community.ovhcloud.com/u/Driver)\
**Post date:** [September 24, 2026, 3:46pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/3 "2026-09-24T15:46:50Z")

</div>

Thank you for taking the time to look into my problem.

Your solution works, thank you.

In my test environment I placed the PHPMailer directory inside the www directory and the test.php file inside the PHPMailer directory.

In your answer you tell me

> If your `src` folder isn’t in the same directory as `test.php`, adjust the path accordingly.

Wanting to use PHPMailer in multiple directories, I placed the test.php file in an "essai" directory and tried to adjust the path like this

> require **DIR**. '/PHPMailer/src/PHPMailer.php';

That doesn’t work; the warning returns the path www/essai/PHPMailer/src/PHPMailer.ph, so the path is not correct.

---

<div class="post-metadata">

**Author:** ![sturpin](https://community.ovhcloud.com/user_avatar/community.ovhcloud.com/sturpin/32/30025_2.png) [@sturpin](https://community.ovhcloud.com/u/sturpin)\
**Post date:** [September 24, 2026, 4:18pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/4 "2026-09-24T16:18:41Z")

</div>

You should use ` __DIR__. '/../PHPMailer/src/PHPMailer.php'`. The `/../` fragment tells PHP to go up one directory before looking for the PHPMailer folder.

Your `require` lines should look like this:

```php
require __DIR__. '/../PHPMailer/src/PHPMailer.php';
require __DIR__. '/../PHPMailer/src/SMTP.php';
require __DIR__. '/../PHPMailer/src/Exception.php';

```

Let me know 😉  
Sergio Turpín

---

<div class="post-metadata">

**Author:** ![sturpin](https://community.ovhcloud.com/user_avatar/community.ovhcloud.com/sturpin/32/30025_2.png) [@sturpin](https://community.ovhcloud.com/u/sturpin)\
**Post date:** [September 24, 2026, 4:27pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/5 "2026-09-24T16:27:47Z")

</div>

The best practice is to use an absolute path defined as a constant in a shared configuration file, or even better, use Composer's **autoloader** if you can.

Since you don't want to use Composer, the cleanest alternative is to define a constant in a file that is always included. For example, create a `config.php` file in **www** with:

```php
<?php
define('PHPMAILER_PATH', '/homez.XXX/tuusuario/www/PHPMailer/src/');

```

Then, in any script, you would just do:

```php
require_once '/homez.XXX/tuusuario/www/config.php';
require PHPMAILER_PATH . 'PHPMailer.php';
require PHPMAILER_PATH . 'SMTP.php';
require PHPMAILER_PATH . 'Exception.php';

```

That way, if you ever move the PHPMailer folder, you only need to change the path in one place 😉

---

<div class="post-metadata">

**Author:** ![Driver](https://community.ovhcloud.com/letter_avatar/driver/32/6_22734026db12803ebb3e059622ac3534.png) [@Driver](https://community.ovhcloud.com/u/Driver)\
**Post date:** [September 24, 2026, 5:11pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/6 "2026-09-24T17:11:37Z")

</div>

It works, apparently I was wrong—I thought that a leading “/” in a path indicated the root directory.

I had started setting up "composer" but it seemed more complicated, so I’ll probably revisit it later for other features.

I’m noting the alternative using the constant.

Again, thank you.

---

<div class="post-metadata">

**Author:** ![sturpin](https://community.ovhcloud.com/user_avatar/community.ovhcloud.com/sturpin/32/30025_2.png) [@sturpin](https://community.ovhcloud.com/u/sturpin)\
**Post date:** [September 24, 2026, 5:17pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/7 "2026-09-24T17:17:02Z")

</div>

If you think any of my answers is the solution, I’d appreciate you clicking the “ **Solution** ” button you’ll find in my answers, so we can help other users with the same problem.

Regards 😉

---

<div class="post-metadata">

**Author:** ![Driver](https://community.ovhcloud.com/letter_avatar/driver/32/6_22734026db12803ebb3e059622ac3534.png) [@Driver](https://community.ovhcloud.com/u/Driver)\
**Post date:** [September 26, 2026, 2:42pm UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/8 "2026-09-26T14:42:31Z")

</div>

I tried the constant and it works fine in all directories and subdirectories.

However, if in a simple form I replace the mail function with the code from my test file above, modified with the constant, I get a 500 error and the error‑display code returns nothing. 🤔

---

<div class="post-metadata">

**Author:** ![sturpin](https://community.ovhcloud.com/user_avatar/community.ovhcloud.com/sturpin/32/30025_2.png) [@sturpin](https://community.ovhcloud.com/u/sturpin)\
**Post date:** [September 27, 2026, 8:52am UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/9 "2026-09-27T08:52:02Z")

</div>

The 500 error you’re seeing now, after the constant works fine in your isolated tests, points directly to a problem with how you’re integrating PHPMailer into the form, not to the library itself.

While we’re here to help each other, this kind of code‑integration error is a bit beyond the scope of what OVHcloud can resolve. The OVH community is great for service configuration, networking, DNS, mail, etc., but for debugging specific PHP code there are more specialized forums and communities that can give you a hand more quickly and precisely.

It’s not that we don’t want to help you, it’s just that the right place sometimes makes all the difference. You’ll get it sorted soon! 😉

Regards,  
Sergio Turpín

---

<div class="post-metadata">

**Author:** ![Driver](https://community.ovhcloud.com/letter_avatar/driver/32/6_22734026db12803ebb3e059622ac3534.png) [@Driver](https://community.ovhcloud.com/u/Driver)\
**Post date:** [September 27, 2026, 10:04am UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/10 "2026-09-27T10:04:53Z")

</div>

I suspect that this is probably about how to integrate PhpMailer into my form.  
Indeed, I understand that the OVH community is mainly there to help with topics directly related to OVH (which is somewhat the case), but considering I won’t be the only one who has to modify its forms, or that some have already done so, I thought that the solved issue in its entirety might be of interest.

Regards

---

<div class="post-metadata">

**Author:** ![system](https://community.ovhcloud.com/user_avatar/community.ovhcloud.com/system/32/5_2.png) [@system](https://community.ovhcloud.com/u/system)\
**Post date:** [September 29, 2026, 10:05am UTC](https://community.ovhcloud.com/t/utilisation-de-php-mailer/53985/11 "2026-09-29T10:05:15Z")

</div>

Ce sujet a été automatiquement fermé après 2 jours. Aucune réponse n'est permise dorénavant.
