I am working on a customer site to add an email contact page. When I go to send the email I get the error:
Mailer Error: SMTP Error: Could not connect to SMTP host.
I am using the PHP FormHandler library found here: https://github.com/justcoded/form-handler
My understanding is that with the cPanel, you simply use the sendmail server on the localhost and do NOT need a username/password. This is the code to send the email, what do I have wrong?
At the moment I have the emails going to my gmail account for testing. Once I get that working I will send it to the customer's Exchange server which has a Barracuda spam filter in front of it.
<?php
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__ . '/vendor/autoload.php');
use JustCoded\FormHandler\FormHandler;
use JustCoded\FormHandler\Handlers\MailHandler;
use JustCoded\FormHandler\DataObjects\MailMessage;
use JustCoded\FormHandler\FileManager\FileManager;
// https://github.com/justcoded/form-handler
$validationRules = [
'fields' => [
'fname' => ['required'],
'lname' => ['required'],
'email' => ['required', 'email'],
'message' => [ 'required', ['lengthMin', 5] ]
], // according to Valitron doc for mapFieldsRules.
'labels' => [
'name' => 'Name',
'email' => 'Email address',
'message' => 'Message',
] // according to Valitron doc.
];
// Mandrill config.
$mailerConfig = [
'mailer' => MailHandler::USE_PHPMAILER,
'host' => 'localhost', // set your smtp host.
'user' => '', // set email.
'password' => '', // set password.
'protocol' => 'FALSE', // 'tls', 'ssl' or FALSE for not secure protocol/
'port' => 25, // your port. (was 587 for tls)
'attachmentsSizeLimit' => 8000000, // around 8MB.
];
$message = [
'from' => ['website@customers.com' => 'webSite'],
'to' => ['<my_account>@gmail.com' => 'me me me'],
'subject' => 'Contact request from {fname} {lname}',
'bodyTemplate' => __DIR__ . '/template-html.php',
'altBodyTemplate' => __DIR__ . '/template-plain.php'
];
$mailer = new MailHandler($mailerConfig, new MailMessage($message));
$formHandler = new FormHandler($validationRules, $mailer);
if ($formHandler->validate($_POST)) {
$formHandler->process();
}
echo $formHandler->response();
exit;
// write errors and return back.
setcookie('advanced_response', $formHandler->response());
header('Location: index.php');
exit;