0

I'm running a personal web server(apache + php + mariaDB).

Using mail() function, I want to send some logs of my personal server to my email.

I wrote the following code and ran it.

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
$to = 'test237814@outlook.com';
$subject = 'SUBJECT';
$body = 'BODY';
$from = 'From: test981879@outlook.com';
if (mail ($to, $subject, $body, $from))
{
    echo '<p>SUCCESS</p>';
}
else
{
    echo '<p>FAILURE</p>';
}
?>

And then I get an error like this:

Warning: mail(): Failed to connect to mailserver at "localhost" port 25,
verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
in D:\xampp\htdocs\mail.php

Of course, mail() returned FALSE(it means the mail delivery failed). And there are no new mails in the mailbox.

So I read this post and followed along: How to configure XAMPP to send mail from localhost?

However, the above solution has two problems.

  1. The sender may use an email address other than Google email. The above method is explained only on the premise of using Google email.
  2. Even if the sender uses Google email, according to the above solution, there is a delay of 4~5 seconds for the mail() function of php to execute. This is too long.

The version of xampp applied to my personal server is as follows: xampp-portable-windows-x64-7.3.25-0-VC15.zip (No MercuryMail and FileZilla)


The following links are some of the posts I referenced to solve this problem:

PHP mail function doesn't complete sending of e-mail

How to configure XAMPP to send mail from localhost?

Saturn
  • 55
  • 10
  • 1. No, the given example is just an config example. You can insert as a sender what you want. 2. Why do you assume a delay? And why it's that important? Keep in mind, that sending a mail is dependent on many factors which can lead to delays. – Jim Panse Jan 05 '21 at 09:12
  • You need to be running a mail server locally. If your os is windows see https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc772058(v=ws.10)?redirectedfrom=MSDN – Eden Moshe Jan 05 '21 at 09:12
  • @JimPanse According to my tests, there is still a significant amount of lag(=delay), causing the page to display very slowly. – Saturn Jan 05 '21 at 09:17
  • @EdenMoshe Thanks a lot. I will learn more about how to create a mail server. – Saturn Jan 05 '21 at 09:20
  • Okay, so what is the point thats bothering you? Page reload delay of receiving the email after it was sent? – Jim Panse Jan 05 '21 at 09:20
  • @JimPanse The problem is that there is a serious delay when the php page containing mail() is opened. – Saturn Jan 05 '21 at 09:27
  • In most php based applications, time consuming stuff is done using some async mechanism like queues. So you would save all data relevant for mailing somewhere and let a background process doing the real sending stuff – Jim Panse Jan 05 '21 at 09:40
  • @JimPanse Thank you. Sounds like an inevitable situation. – Saturn Jan 05 '21 at 09:44

0 Answers0