How to install phpMailer
in a shared hosting environment? I need to use this for email verifications and password changing of the users.
PHPMailer will be installed and you'll be ready to use it. Composer will generate an “autoload. php” file you can use to include the installed libraries, in this case PHPMailer. This file is located under the “vendor” directory by default, although you can configure Composer to use a different directory name.
If you've installed it manually, just download the latest version from Github and replace your current version. OK, so just search for one of its files from a shell: find / -name class. phpmailer. php , or use locate if you have that installed.
First download PHPMailer from Github. Extract the archive and upload the content to a folder on your web server . Create or modify your mail sending code with the following: use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'src/Exception.
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 = "[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!";
}
?>
Make sure to enable "non secure apps" in this GMAIL account too: https://support.google.com/accounts/answer/6010255?hl=en
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With