新安装后使用PHPMailer时出错

时间:2017-11-29 20:49:57

标签: php email syntax-error phpmailer

我刚刚下载了PHPMailer压缩文件,将其保存到我的主机服务器并安装/解压缩了PHPMailer文件。当我添加一个require语句来使用PHPMailer.php文件时,我收到以下错误消息:

  

解析错误:语法错误,意外' ['在第288行的D:\ InetPub \ vhosts \ ******。com \ *********。\ language \ PHPMailer \ src \ PHPMailer.php

这是不是意味着PHPMailer.php文件中存在错误?如果是,是否有可以在其位置使用的更正文件?这是我试图运行的php代码:

<?php

ini_set('include_path','D:\inetpub\vhosts\******.com\*********.com\included_files;D:\inetpub\vhosts\******.com\*********.com\referenced_files;D:\inetpub\vhosts\******.com\*********.com\language;D:\inetpub\vhosts\******.com\*********.com\language\PHPMailer;D:\inetpub\vhosts\******.com\*********.com\language\PHPMailer\language;D:\inetpub\vhosts\******.com\*********.com\language\PHPMailer\src');

include("incPHP1.inc");

require 'Exception.php';
require 'PHPMailer.php';
require '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 = $mailHost;  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = $mailUser;                 // SMTP username
    $mail->Password = $mailPassword;                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('*******@rlchealth.com', 'Mailer');
    $mail->addAddress('****@rlchealth.net', 'Joe User');     // Add a recipient
    $mail->addAddress('*********@rlchealth.com');               // Name is optional
    $mail->addReplyTo('********@rlchealth.com', 'Information');
    $mail->addCC('************@*****.com');
    $mail->addBCC('************r*****l.com');

    //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.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}

?>

1 个答案:

答案 0 :(得分:1)

这个问题是你的PHP版本我猜你使用的是php 5.3而phpMiller是5.6。

请更改您的php版本,然后重试。