[英]PHPMailer: Parse error on the line 'composer install'
I am trying to use PHPMailer on GoDaddy, this is my first time using it - however, it gives me the error;我正在尝试在 GoDaddy 上使用 PHPMailer,这是我第一次使用它 - 但是,它给了我错误;
Parse error: syntax error, unexpected 'install' (T_STRING)
; Parse error: syntax error, unexpected 'install' (T_STRING)
; on the line composer install
, what is wrong?就行
composer install
,有什么问题? I have looked around at other posts and played around with the code but I still cannot figure out what is wrong.我已经查看了其他帖子并使用了代码,但我仍然无法弄清楚出了什么问题。 Any help is greatly appreciated!
任何帮助是极大的赞赏!
<?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}";
}
note : If you are using a shared hosting on go daddy and not a dedicated server, I think you will not be able to run the composer, you will only use the SMTP configuration注意:如果您在 go 上使用共享主机而不是专用服务器,我认为您将无法运行作曲家,您将只能使用 SMTP 配置
otherwise try this否则试试这个
Run the commands via the command line.通过命令行运行命令。
composer require phpmailer/phpmailer
A folder called vendor will appear in your directory一个名为 vendor 的文件夹将出现在您的目录中
Your php file should look like this您的 php 文件应如下所示
index.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}";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.