So I'm pretty new to all of this and I took up a small project of mine as a challenge. I have a contact form on my website and I want that contact form to be sent to a private email (namecheap).
I'm running Ubuntu v18. I installed PHPmailer and Composer (accidentally on root which I don't think I was supposed to.)
I talked to namecheap and I followed their instructions:
If you want to use Private Email service in your contact form, it's not possible to set up PHP Mail() function since messages will be sent from a third-party server. In this case, it's required to use SMTP authentication instead. Here are the details that should be used:
SMTP username: your email address
SMTP password: password for this email account
SMTP host: mail.privateemail.com
SMTP port: 465 with SSLAlso, please note that the 465 port should be opened on your hosting server.
Yes, sure. However, instead of PHP Mail function, the SMTP Authentication method should be used.
my welcome.php code below:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
ini_set('display_errors', 1);
//Load Composer's autoloader
require '/root/vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 1; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.privateemail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'contact@mydomain.io'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('myemail@gmail.com', 'Testing User');
$mail->addAddress('contact@mydomain.io', 'Joe User'); // Add a recipient
//Attachments
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
So the errors that I'm currently getting:
Warning: require(/root/vendor/autoload.php): failed to open stream: Permission denied in /var/www/html/welcome.php on line 9
Fatal error: require(): Failed opening required '/root/vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/html/welcome.php on line 9
I am using shockhosting and I requested them to open up that port. I believe I was supposed to do that?
Anyways, I'm really stuck and I want to learn how to properly accomplish this so it can work. Thank you!