【发布时间】: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