Using the following setup;
- PHP version: 5.3.3
- PHPMailer version: 6.0.5
- CentOS release: 6.9
I manually downloaded the PHPMailer ZIP from the github source, extracted the files onto my local Win 10 PC, then FTP'd them to a remote folder on the CentOS machine (var/www/html/mysite/lib/PHPMailer
).
I created the file mysite/mailer.php
and the contents are identical to the example on github (path names changed to reflect my config) - see below;
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'lib/PHPMailer/src/Exception.php';
require 'lib/PHPMailer/src/PHPMailer.php';
require 'lib/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
?>
Without changing any of the config settings, when I visit mydomain.com/mailer.php
I see the following error;
Parse error: syntax error, unexpected '[' in /var/www/html/mysite/lib/PHPMailer/src/PHPMailer.php on line 304
Line 304 of PHPMailer.php contains;
public $SMTPOptions = [];
I've tried entering my own SMTP details in the mailer.php
file but I still receive the same error.
Any ideas what the issue is?
Any help is appreciated.