Which Directory Should I Install the PHPMailer?

Sorry for this noob question but I am honestly lost. I managed to install composer with the help of dcblog.dev, now I am trying to install PHPMailer. This is my case:

I have a nanode running two Drupal 9 websites. Locations:
Site1: /var/www/site1.com
Site2: /var/www/site2.com

Site2 is using ElasticEmail to send mails and it is working even before I installed composer.

Site1 is intended to use NC's privateemail.com, hence, I need PHPMailer in my server.

So where should I install PHPMailer? I already tried the root / also the my ~ and also at /var/www/site1.com/. But from this three locations, Site1 can't send email.

Here is the code I use to install the PHPMailer:

composer require phpmailer/phpmailer

Now I am stuck and don't know where to go. I already removed all the files created by above command to clean up.

I don't know what I miss. Do I need to configure PHPMailer first for it to work?

1 Reply

As a matter of course, I would install PHPMailer wherever your index.php is. For example, here's the file layout for a site that I have:

total 120
drwxr-xr-x  6 stevewi stevewi  4096 Jul 28  2018 app
drwxr-xr-x  7 stevewi stevewi  4096 Aug 22  2018 assets
-rw-r--r--  1 stevewi stevewi   410 Apr 23  2020 composer.json
-rw-r--r--  1 stevewi stevewi 59035 Apr 23  2020 composer.lock
-rw-r--r--  1 stevewi stevewi  1091 Aug 23  2018 htaccess
drwxr-xr-x  2 stevewi stevewi  4096 Aug 20  2018 imagelib
-rw-r--r--  1 stevewi stevewi  1494 Aug 23  2018 index.php
-rw-r--r--  1 stevewi stevewi  2696 Aug  1  2018 install.me
-rw-r--r--  1 stevewi stevewi  2696 Aug  1  2018 read.me
-rw-r--r--  1 stevewi stevewi   896 Aug 23  2018 robots.txt
-rwxr-xr-x  1 stevewi stevewi  5653 Aug 22  2018 setup
drwxrwxrwx  3 stevewi stevewi  4096 Jul 28  2018 tmp
drwxr-xr-x  3 stevewi stevewi  4096 Aug 23  2018 var
drwxr-xr-x 16 stevewi stevewi  4096 Apr 23  2020 vendor
drwxr-xr-x  4 stevewi stevewi  4096 Aug 20  2018 www

You write:

Here is the code I use to install the PHPMailer:
composer require phpmailer/phpmailer

I would put this in composer.json like this:

{
    "require": {
        "phpmailer/phpmailer": "*"
    }
}

Then, all you have to do is run composer install or composer update… See here for basic composer info and the format for composer.json:

https://getcomposer.org/doc

All the composer packages are installed in vendor (by default…you can change this if you like):

-rw-r--r--  1 stevewi stevewi  178 Apr 23  2020 autoload.php
drwxr-xr-x  3 stevewi stevewi 4096 Apr 13  2020 bcosca
drwxr-xr-x  2 stevewi stevewi 4096 Apr 23  2020 bin
drwxr-xr-x  7 stevewi stevewi 4096 Apr 23  2020 composer
drwxr-xr-x  3 stevewi stevewi 4096 Aug 22  2018 filp
drwxr-xr-x  3 stevewi stevewi 4096 Apr 13  2020 justinrainbow
drwxr-xr-x  3 stevewi stevewi 4096 Apr 13  2020 masterminds
drwxr-xr-x  3 stevewi stevewi 4096 Apr 23  2020 nesbot
drwxr-xr-x  4 stevewi stevewi 4096 Apr 13  2020 psr
drwxr-xr-x  3 stevewi stevewi 4096 Apr 13  2020 respect
drwxr-xr-x  3 stevewi stevewi 4096 Aug 22  2018 sabre
drwxr-xr-x  4 stevewi stevewi 4096 Apr 13  2020 seld
drwxr-xr-x  3 stevewi stevewi 4096 Apr 13  2020 simplepie
drwxr-xr-x  3 stevewi stevewi 4096 Aug 22  2018 suin
drwxr-xr-x 13 stevewi stevewi 4096 Apr 13  2020 symfony

You write:

Do I need to configure PHPMailer first for it to work?

Yes, you need to configure some basic information for it to work correctly (like the mail server's domain name or IP address). Typically, this information would be coded in your index.php. For more information, see:

https://github.com/PHPMailer/PHPMailer

There's a wiki at https://github.com/PHPMailer/PHPMailer/wiki

Lastly, if your site is going to send email, you need to be aware of this:

https://www.linode.com/community/questions/20605/ports-25-465-and-587-egress-blocked

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct