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.)

phpmailer directory

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 SSL

Also, 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:

// 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

    $mail->setFrom('myemail@gmail.com', 'Testing User');
    $mail->addAddress('contact@mydomain.io', 'Joe User');     // Add a recipient


    $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';

    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!

  • I changed tls to ssl. I changed a few things around. Now I'm getting a is currently unable to handle this request. HTTP ERROR 500 – ONIS Oct 9 '18 at 5:07
  • shockhosting replied to my ticket and said "We don't block any ports by default so it should be open." – ONIS Oct 9 '18 at 5:17
  • Error Logs: [Tue Oct 09 05:34:20.564909 2018] [php7:error] [pid 1310] [client ip] PHP Fatal error: require(): Failed opening required '/root/vendor/phpmailer/phpmailer/src/Exception.php' (include_path='.:/usr/share/php') in /var/www/html/welcome.php on line 4 – ONIS Oct 9 '18 at 5:43

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.