How to install phpMailer in a shared hosting environment?

南楼画角 提交于 2019-12-12 17:21:19

问题


How to install phpMailer in a shared hosting environment? I need to use this for email verifications and password changing of the users.


回答1:


You can download it here: https://github.com/PHPMailer/PHPMailer

Upload the folder to your server and include the main file with this line:

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

After that, you will need an external SMTP account, like gmail.com for example. Here is a working example of PHPMailer with 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 = "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!";
}
?>

Make sure to enable "non secure apps" in this GMAIL account too: https://support.google.com/accounts/answer/6010255?hl=en



来源:https://stackoverflow.com/questions/40813626/how-to-install-phpmailer-in-a-shared-hosting-environment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!