I have looked through the threads here and think I might need to check my server log for more info. I didn’t see any logs under my php or logs folder for todays date when I installed and started using PHPmailer. I am not sure what to do next. I have installed PHPmailer in my public folder and called the class per the install instructions. I am just trying to validate the SMTP connection before going trying to build a contact form. Here is the code that is generating the error:
/**
- This uses the SMTP class alone to check that a connection can be made to an SMTP server,
- authenticate, then disconnect
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don’t have access to that
date_default_timezone_set(‘America/Denver’);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require ‘/home/talktodo/domains/mydomain.com/public_html/PHPMailer/src/Exception.php’;
require ‘/home/talktodo/domains/mydomain.com/public_html/PHPMailer/src/PHPMailer.php’;
require ‘/home/talktodo/domains/mydomain.com/public_html/PHPMailer/src/SMTP.php’;
//Create a new SMTP instance
$smtp = new SMTP;
//Enable connection-level debug output
$smtp->do_debug = SMTP::DEBUG_CONNECTION;
try {
//Connect to an SMTP server
if ($smtp->connect(‘mail.mydomain.com’, 587)) {
//Say hello
if ($smtp->hello(‘mydomain.com’)) { //Put your host name in here
//Authenticate
if ($smtp->authenticate(‘[email protected]’, ‘password’)) {
echo “Connected ok!”;
} else {
throw new Exception('Authentication failed: ’ . $smtp->getLastReply());
}
} else {
throw new Exception('HELO failed: '. $smtp->getLastReply());
}
} else {
throw new Exception(‘Connect failed’);
}
} catch (Exception $e) {
echo 'SMTP error: '. $e->getMessage(), “\n”;
}
//Whatever happened, close the connection.
$smtp->quit(true);