如何在共享主机环境中安装phpMailer?

时间:2016-11-25 23:57:48

标签: phpmailer

如何在共享托管环境中安装phpMailer?我需要将其用于电子邮件验证和用户密码更改。

1 个答案:

答案 0 :(得分:2)

您可以在此处下载:https://github.com/PHPMailer/PHPMailer

将文件夹上传到您的服务器并使用以下行包含主文件:

<?php
require 'phpmailerfolder/PHPMailerAutoload.php';
?>

之后,您将需要一个外部SMTP帐户,例如gmail.com。以下是带有GMAIL的PHP​​Mailer的工作示例:

<?php
require 'phpmailerfolder/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "youremail@gmail.com";
$mail->Password = "yourpassword";
$mail->setFrom('youremail@gmail.com', 'Your Name');
$mail->addAddress('to@site.com', 'To');

$mail->Subject = "Subject";
$mail->Body    = "Message";

if (!$mail->send()) {
echo "Error sending message";
} else {
echo "Message sent!";
}
?>

确保启用&#34;非安全应用&#34;在此GMAIL帐户中:https://support.google.com/accounts/answer/6010255?hl=en

相关问题