PHPMailer语法错误全新安装

时间:2018-05-24 13:48:34

标签: php linux centos smtp phpmailer

使用以下设置;

  • PHP版本:5.3.3
  • PHPMailer版本:6.0.5
  • CentOS版本:6.9

我从github source手动下载了PHPMailer ZIP,将文件解压缩到我当地的Win 10 PC上,然后通过FTP将它们移到CentOS机器上的远程文件夹(var/www/html/mysite/lib/PHPMailer)。

我创建了文件mysite/mailer.php,其内容与github上的示例相同(路径名称已更改以反映我的配置) - 请参阅下文;

<?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;
}

?>

在不更改任何配置设置的情况下,当我访问mydomain.com/mailer.php时,我看到以下错误;

  

解析错误:语法错误,意外&#39; [&#39;在   第304行/var/www/html/mysite/lib/PHPMailer/src/PHPMailer.php

PHPMailer.php的第304行包含;

public $SMTPOptions = [];

我已尝试在mailer.php文件中输入我自己的SMTP详细信息,但仍然收到相同的错误。

任何想法是什么问题?

感谢任何帮助。

0 个答案:

没有答案