问题
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