如何安装phpMailer
在共享托管环境中?我需要用它来验证电子邮件和更改用户的密码。
你可以在这里下载:https://github.com/PHPMailer/PHPMailer
将文件夹上传到您的服务器并包含以下行的主文件:
<?php
require 'phpmailerfolder/PHPMailerAutoload.php';
?>
之后,您将需要一个外部 SMTP 帐户,例如 gmail.com。以下是 PHPMailer 与 GMAIL 的工作示例:
<?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 = "[email protected]";
$mail->Password = "yourpassword";
$mail->setFrom('[email protected]', 'Your Name');
$mail->addAddress('[email protected]', 'To');
$mail->Subject = "Subject";
$mail->Body = "Message";
if (!$mail->send()) {
echo "Error sending message";
} else {
echo "Message sent!";
}
?>
确保在此 GMAIL 帐户中也启用“非安全应用程序”:https://support.google.com/accounts/answer/6010255?hl=en
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)