Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install phpMailer in a shared hosting environment?

Tags:

phpmailer

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

like image 543
Dumb Question Avatar asked Nov 25 '16 23:11

Dumb Question


People also ask

Where do I put PHPMailer?

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.

How do I know if PHPMailer is installed?

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.

How can I download PHPMailer without composer?

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.


1 Answers

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

like image 53
bruno Avatar answered Oct 29 '22 05:10

bruno