Search code examples
phpemailsmtpdigital-oceanlamp

What is the simplest way to authenticate and send email from my mailbox via DO LAMP


I have a LAMP (on DigitalOcean) and want to authenticate with my webmail provider (which supports IMAP over SSL/TLS) and send emails. I have done this many times from a symfony application using various symfony extensions, but this is a flat PHP application and I want to keep it as lightweight as possible. Which of the following options would bring the least overhead/be the least invasive on my application?

PHPMailer

According to this (old) page https://www.digitalocean.com/community/questions/how-to-configure-lamp-with-ubuntu-to-send-email-from-php-through-office365 it seems a LAMP on DigitalOcean used to have native support for PHPMailer but that doesn't seem to be the case anymore, the following code

   //Send the email
    $mail = new PHPMailer(true);
    $mail->Host = "mailcluster.loopia.se";
    $mail->Port       = 465;

Gives me the following error

Uncaught Error: Class "PHPMailer" not found

so unless I need to include/require some reference to a PHPMailer library in my application (?) the marketplace LAMP doesn't seem to have it anymore. I suppose I could download relevant files (PHPMailer, SMTP and Exception files from the PHPMailer repo? https://github.com/PHPMailer/PHPMailer/tree/master) and put in my application directory.

Sendmail

Looking at phpinfo() Apache has Sendmail installed, but I don't think this provides the option to do SSL auth towards my mailbox as far as I have read?

Postfix

My server already has Postfix 3.4.10 installed, is this a way to go here? It seems that postfix is a way to turn my server into a mail client (?) and do something different than what I am after, but perhaps it offers that feature as well? Like I mentioned, if this can be accomplished without ading any other packages or libraries, that would be the best choice for this application.


Solution

  • DigitalOcean hosting typically allows shell access (by SSH) and so you can use composer to install the phpmailer package

    Alternatively, you may download the phpmailer (zip file) , uncompress it and then upload the directory by FTP

    I am sure that both are ok (composer install or FTP upload) but composer would be easier for most users. However, if your DO subscription does not allow SSH access then you may be forced to use the FTP way

    For your case, you are talking about sending emails out (SMTP) and of course if you are using SSL/TLS it will be better in terms of security. Install the phpmailer and then you are fine to set it to use your current, external SMTP server with SSL/TLS

    On the other hand, "sendmail" and "postfix" are two different mail server daemons. Both of them allows you to send / receive emails (with or without SSL/TLS). A server typically can serve multiple purposes so you can use a linux / unix server (in your case DO) to be both a web server, mysql server, ftp server and mail server, etc.