Search code examples
phpphpmailerbitnami

PHP mailer works on Local Machine but not on AWS LightSail server


My Problem is that PHP mailer works on my local machine, but does not work when I deploy the script to my AWS Lightsail server.

I have tried setting the proper file (644) and folder(755) permissions, still nothing works.

I have the function deployed on other servers, without any issue

The error message

PHP Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in

How I include the mail function require('transit/mail.php');

The content of my mail function.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';

function send_mail($sender, $senderName, $recipient, $subject, $bodyText, $bodyHtml){

Solution

  • I have solved the issue. These are the steps I followed.

    1. Connect to the server via ssh terminal
    2. Navigate to the php mailer folder
      1. Run composer require phpmailer/phpmailer

    This was the message received.

    Using version ^6.1 for phpmailer/phpmailer ./composer.json has been created Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Writing lock file Generating autoload files

    It worked afterwards.