# Uniform and PHPMailer works on localhost but not on server

**URL:** <https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 24, 2018, 1:51pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678 "2018-06-24T13:51:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoine1000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/antoine1000/32/4322_2.png) [@antoine1000](https://forum.getkirby.com/u/antoine1000)\
**Post date:** [June 24, 2018, 1:51pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/1 "2018-06-24T13:51:15Z")

</div>

Hi,

I’m using Uniform and PHPMailer as it is explained [here](https://forum.getkirby.com/t/contact-form-with-phpmailer-uniform/6469/5).

Everything is working fine on my localhost server (I use SMTP and everything, I receive emails as expected) but on my server, I got the following error after submitting the form :

`There was an error sending the form: The email service is not available: phpmailer`

I guess this is because Uniform can’t find the phpmailer service, but I don’t know why and how to fix this.

PHPMailer files are in `site/plugins/PHPMailer-driver/`.

My `phpmailer-driver.php` looks like that :

```auto
<?php
use PHPMailer\PHPMailer\PHPMailer;

email::$services['phpmailer'] = function($email) {
    require_once( __DIR__. DS . 'PHPMailer.php');
    require_once( __DIR__. DS . 'SMTP.php');

    $mail = new PHPMailer();

    //Tell PHPMailer to use SMTP
    $mail->isSMTP();
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 2;
    //Set the hostname of the mail server
    $mail->Host = 'ssl0.ovh.net';
    //Set the SMTP port number - likely to be 25, 465 or 587
    $mail->Port = 587;
    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    //Username to use for SMTP authentication
    $mail->Username = 'myemail@email.com';
    //Password to use for SMTP authentication
    $mail->Password = 'mypassword';

    $mail->CharSet = 'UTF-8';
    $mail->setFrom($email->from);
    $mail->addReplyTo($email->replyTo);
    $mail->addAddress($email->to);

    $mail->isHTML(true);
    $mail->Subject = $email->subject;
    $mail->Body = $email->body;

    if (!$mail->send()) {
        throw new Error('PHPMailer error: ' . $mail->ErrorInfo);
    }
}
?>

```

and the action in my controller looks like that :

```auto
// ... 
if (r::is('POST')) {
        $form->emailAction([
            'to' => 'to@exemple.com',
            'from' => 'from@exemple.com',
            'service' => 'phpmailer',
            'snippet' => 'email-html'
        ]);
    }

```

Do you have an idea from where the error `The email service is not available: phpmailer` came from ? Why Uniform can find it on localhost but not on my server ?

Thank you ! 😁

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 24, 2018, 2:03pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/2 "2018-06-24T14:03:18Z")

</div>

> [@antoine1000](#):
>
> `PHPMailer-driver/` .
> 
> My `phpmailer-driver.php` l

One possible issue: use lower case characters in both your folder and file name.

---

<div class="post-metadata">

**Author:** ![antoine1000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/antoine1000/32/4322_2.png) [@antoine1000](https://forum.getkirby.com/u/antoine1000)\
**Post date:** [June 24, 2018, 2:29pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/3 "2018-06-24T14:29:05Z")

</div>

Thank you for your quick answer !

I guess that was it, because I have now an issue with PHPMailer not founding `Exception` (Kirby CMS Debugger tells me : `Class 'PHPMailer\PHPMailer\Exception' not found`, even though I added `Exception.php` to my folder and require it in my `phpmailer-driver.php` file ) ; but at least `phpmailer` service is found now !

I will try to debug it myself.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 24, 2018, 2:32pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/4 "2018-06-24T14:32:47Z")

</div>

You have to add the use directive as well

```auto
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

```

---

<div class="post-metadata">

**Author:** ![antoine1000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/antoine1000/32/4322_2.png) [@antoine1000](https://forum.getkirby.com/u/antoine1000)\
**Post date:** [June 24, 2018, 2:43pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/5 "2018-06-24T14:43:05Z")

</div>

Yes I did that, the beggining of my `phpmailer-driver.php` file looks like that :

```auto
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

email::$services['phpmailer'] = function($email) {
    require_once( __DIR__. DS . 'PHPMailer.php');
    require_once( __DIR__. DS . 'SMTP.php');
    require_once( __DIR__. DS . 'Exception.php');

    $mail = new PHPMailer();

// options...etc

```

but the error still happening (`Exception.php` file is on the server, I checked with Cyberduck, just to be sure)

 ![exception-error](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/0/043b90baf99f1e398ee5e38846037519d43bbcfd.jpg)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 24, 2018, 3:01pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/6 "2018-06-24T15:01:57Z")

</div>

Maybe you have to require the Exception class first.

---

<div class="post-metadata">

**Author:** ![antoine1000](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/antoine1000/32/4322_2.png) [@antoine1000](https://forum.getkirby.com/u/antoine1000)\
**Post date:** [June 24, 2018, 3:11pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/7 "2018-06-24T15:11:28Z")

</div>

It works now ! Thank you for your help, I know it was not a Kirby-related issue but it could help someone else to know that you need to **name your folder with lowercase**!

Have a nice day ! 😁

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:27pm UTC](https://forum.getkirby.com/t/uniform-and-phpmailer-works-on-localhost-but-not-on-server/10678/8 "2025-02-06T17:27:56Z")

</div>

Archived on February 6, 2025, 5:27pm UTC


