Phpmailer不在网络服务器上工作

时间:2018-03-15 19:35:23

标签: php phpmailer

我想让phpmailer在Web服务器上工作。它在我的xampp服务器上没有问题,但是当我把它放在Web服务器上时它无法找到它们并且它给了我错误。我也尝试将它放在另一个Web服务器上,但这不起作用。我还将文件从我的xampp服务器复制到了Web服务器,但仍然无效。

use PHPMailer\PHPMailer\PHPMailer; (line 3)
use PHPMailer\PHPMailer\Exception; (line 4)


Error: parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '('email.php on line 3

错误指向的代码是

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function sendemail(){



require '../mail/src/PHPMailer.php';
require '../mail/src/SMTP.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    include "removed(was database)";
    $name = $_POST['name'];
    $Uemail = $_POST['email'];
    $select = $_POST['select'];
    $issue = $_POST['issue'];
    $resolution = $_POST['resolution'];
    $datesubmited = date("Y-m-d H:i:s");
    //Server settings
    $mail->SMTPDebug = 4;  //1-4                               // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'removed';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'removed';                 // SMTP username
    $mail->Password = 'removed';                           // SMTP password
    $mail->SMTPSecure = '';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = removed;                                    // TCP port to connect to

    //Recipients
    $email = 'removed'; //put in default email that corresponds with the username / passwoard.
    $mail->setFrom( $email, 'removed');
    $mail->addAddress($Uemail, $name);
    $mail->addAddress('removed', 'removed');
    $mail->addAddress('removed', 'removed');     // Add a recipient
    // $mail->addAddress('', $name);


    //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 = 'Request from ' . $name;
    $mail->Body    = 'Details ' . "<br>" .
    "Date: " . $datesubmited . "<br>" .
    "Name: " . $name . "<br>" .
    "Email Address: " . $email . "<br>" .
    "Area of Concern: " . $select . "<br>" . 
    "Issue: " . $issue . "<br>" .
    "Suggested Resolution: " . $resolution . "<br>"; 




    $mail->AltBody = 'Hello '. $name . ' your request has been sumbited!'.'</b>';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
    $mail->send();
    echo "Thank you " . $name . " for your submission." . "<br>" . "Someone will repsond to you shortly.";
    echo "<br>";
    echo "Go back home " . "removed" ;
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
} 




?>

1 个答案:

答案 0 :(得分:0)

乍一看,我会说use函数似乎称之为问题。您可以尝试在第一次use来电之前添加这些行并检查结果:

$funcDefinition = new ReflectionFunction('use');
print $funcDefinition->getFileName() . ', ' .
  $funcDefinition->getStartLine();

检查本地和远程系统上的呼叫结果并比较结果。我不认为您正在部署在use命令不可用的Pre-PHP-5.3系统上,但请同时添加一些有关本地和远程使用的不同PHP版本的信息。

实际上似乎,如果您在PHP 5.2系统上进行部署,则会收到您的错误消息,如此SO thread所述。因此,首先检查必须是PHP版本(即在第一次phpinfo();电话之前添加use。)

结论:问题作者因没有use支持在PHP 5.2系统上部署而收到错误。