Do I need a email server? Why is my email slow?

So my initial setup I used php sendmail for a long time everything worked great aside from me going to spam recently 1-2 months ago I noticed any task on my website related to an email (account created verification email sent) it would take around 5 minutes to finish (function returns only after sending email) wondering why it went from instant every time to 5 minutes every time I looked it up all I really got was people saying it can take up to 5 minutes to send and that using a mail server would help still really confused how the time went from instant to very slow do I need a mail server? if so what set up or guide should I use? any help would be great im really new to all this.

Ubuntu 20.04 LTS, Linode 8GB: 4 CPU, 160GB Storage, 8GB RAM
9000inc.com

function SendEmail($TO, $FROM, $SUBJECT, $MSG)
{
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "Reply-To: <{$FROM}>\r\n";
$headers .= "Return-Path: <{$FROM}>\r\n";
$headers .= "From: <{$FROM}>\r\n";
if(mail($TO, $SUBJECT, $MSG, $headers))
{
return $MSG;
}
else
{
return 'Error Sending Email.';
}
}//this way of sending emails takes around 5 minutes everytime but use to be instant sad…

7 Replies

This behavior is certainly disconcerting. I'd be happy to try assisting you here.

Even without your code changing, it is entirely possible that recent updates or changes to your application stack could be affecting the performance of your Linode. From an Ubuntu environment, you may review your Linode's history of updates by reading through the /var/log/dpkg.log file.

No matter what your Linode's update history states, your Linode's log files should be able to provide you some deeper information as to why these emails are taking so long to send. We have another page on our Community Questions site documenting how to check your Linode's log files:

It sounds like there are several components in your log files, so it is important to review at least the following log files to get a complete picture of what's happening:

  • sendmail's log files
  • PHP's log files
  • Your web server log files (if running PHP in combination with a web server)

Your applications can generate log entries for events ranging from catastrophic failures to mundane procedural events. By default, most applications will not log the more mundane events that they could potentially log. Excluding these events from being logged has several important effects:

  • reduces the amount of processing power devoted to logging, which can become excessive when recording every single action the application is taking
  • critical errors are easier to notice when not surrounded by loads of more mundane actions
  • keeps the size of the log files small, which helps prevent your Linode's disk from filling up

While this behavior generally has advantages for your Linode's operation, you might need to configure your applications to log more events than they normally do in order to troubleshoot this specific issue. This behavior is called the "logging level" of an application, and each application has a different way of editing its logging level.

PHP uses the error_reporting configuration setting:

sendmail uses the following values for configuring its log level:

It's not clear if you are using a web server, but I'd like to provide some links to the documentation of the two most popular web servers, Nginx and Apache.

Nginx specifies the log level at the end of its error_log directive:

Apache uses the LogLevel directive:

When changing the log level (or making any other configuration changes to your Linode's applications), it is important to reload or restart the services, which you can achieve using systemctl:

To avoid excessive resource utilization on your Linode, it is important to change these settings back to their defaults once you complete this task. This will also require a reload through systemctl.

Managing a mail server is a tricky task. To help you out with this as best as possible, we have a guide to assist you with running a mail server:

I hope you find this information helpful! Please feel free to ask any follow-up questions you may have.

Thank you I will be sure to check into all this asap really need to get email speeds back to normal lol and yes I am using apache id like to eventually upgrade to a mail server hopefully your advice will fix the current issue for now till I find some time to figure out all the mail server stuff

@calofduty9000

As the operator of a low-volume mail server, I can testify from my own experience that it takes a lot of care & feeding.

If what you previously described is all you want to use a mail server for, I would seriously reconsider. You’re going to spend a lot of time tending it…probably far more than you know.

You can use Gmail or some such to handle the mail your php app generates with far less hassle.

— sw

Thanks for the advice I have looked in to google and some others as well of course the reason that drove me to linode I love how they give you all the tools basically for free as they should be you just have to know how to use them eventually we may want a more advanced mail system for supporting users I am just hoping for now to troubleshoot it and get it fixed till we need to upgrade

@calofduty9000 --

I think you may have misunderstood… You can use Gmail to send mail from your Linode without diving into the Google Apps pool…Gmail provides the mail-transfer agent (MTA) only. There is some (fairly modest) setup required but that's about it.

If your only use for email is using the snippet of php(1) code you posted in your OP to send advertising or newsletters or operate a mailing list, I would seriously consider doing what I suggest. You'll save yourself a lot of lost weekends…

-- sw

Oh I did not know they offer free services as far as that goes thought it was just their app suite I will for sure check into that hopefully their api makes a little more sense then the others I have looked into lol

There are several threads in this forum started by people asking how to use Gmail as an MTA. You should probably start by looking at them.

Search is your friend ;-)

-- sw

PS. Starting with Gmail and then moving (slowly) toward a self-managed server would be a good strategy IMHO…especially if your volume is currently low; you expect it to grow; and you need to educate yourself a lot. You'll buy yourself a lot of (valuable) time…

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