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.
- The sender may use an email address other than Google email. The above method is explained only on the premise of using Google email.
- 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: