Hi,
I’m using Uniform and PHPMailer as it is explained here.
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 :
<?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 :
// ...
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 !