【问题标题】:PHPMailer: Parse error on the line 'composer install'PHPMailer:“composer install”行上的解析错误
【发布时间】:2020-08-16 16:17:12
【问题描述】:

我正在尝试在 GoDaddy 上使用 PHPMailer,这是我第一次使用它 - 但是,它给了我错误; Parse error: syntax error, unexpected 'install' (T_STRING);在线composer install,怎么了?我查看了其他帖子并使用了代码,但我仍然无法弄清楚出了什么问题。 非常感谢任何帮助!

 <?php

composer install
composer require phpmailer/phpmailer

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;  
    $mail->isSMTP();    
    $mail->Host       = 'stmp.gmail.com'; 
    $mail->SMTPAuth   = true;  
    $mail->Username   = 'MY EMAIL';  
    $mail->Password   = 'MY PASSWORD'; 
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port       = 465;  

    $mail->setFrom('MY EMAIL', 'MY NAME');

    $mail->addAddress('xxx'); 


    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Subject';
    $mail->Body    = 'This is the main message';
    $mail->AltBody = 'Some body text';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

【问题讨论】:

  • 您需要通过项目根文件夹中的 CMD 启动此命令。它将生成一个带有 PHPMailler 库的供应商文件夹,然后您就可以使用它了。这里有一些东西可以帮助你理解作曲家。 youtube.com/watch?v=I6wm15OWyqg网站作曲家> getcomposer.org

标签: php html phpmailer mail-server


【解决方案1】:

注意:如果您在 go daddy 上使用共享主机而不是专用服务器,我认为您将无法运行 composer,您将只能使用 SMTP 配置

否则试试这个

通过命令行运行命令。

composer require phpmailer/phpmailer

一个名为 vendor 的文件夹将出现在您的目录中

  • root_path/
    • 供应商/
    • index.php

你的 php 文件应该是这样的

index.php

<?php

require 'vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;


$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;  
    $mail->isSMTP();    
    $mail->Host       = 'stmp.gmail.com'; 
    $mail->SMTPAuth   = true;  
    $mail->Username   = 'MY EMAIL';  
    $mail->Password   = 'MY PASSWORD'; 
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port       = 465;  

    $mail->setFrom('MY EMAIL', 'MY NAME');

    $mail->addAddress('xxx'); 


    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Subject';
    $mail->Body    = 'This is the main message';
    $mail->AltBody = 'Some body text';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

【讨论】:

  • 非常感谢!您知道通过 cpanel 执行此操作的任何教程或方法吗?
猜你喜欢
  • 1970-01-01
  • 2017-02-12
  • 2016-06-11
  • 2014-12-21
  • 1970-01-01
  • 2017-08-24
  • 2015-11-24
  • 2019-07-12
  • 2014-01-17
相关资源
最近更新 更多