Php mail error in beginner's application

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Php mail error in beginner's application

Postby Chikwado » 18. December 2023 07:42

Good day administrator

Please the below php function objects is not working in my server.
I'm on window 8.1 x86, xampp 3.2, php 7.2 and trying to send email using the below function object
Code: Select all
mail()
I installed mail client 'thunderbird' and it's working, I have installed mail client 'squirrelmail' and it's working. Now, the php mail() function is not working. Why?
Below are my code:
Code: Select all
<?php
$to = 'recipients@email-address.com';
$subject = 'Hello from XAMPP!';
$message = 'This is a test';
$headers = "From: your@email-address.com\r\n";
if (mail($to, $subject, $message, $headers)) {
 echo "SUCCESS";
} else {
 echo "ERROR";
}
Window8.1 32bits, Code:Block/mingw, web, server, network and latest wine.
User avatar
Chikwado
 
Posts: 38
Joined: 16. July 2014 13:44
Location: Abuja, Nigeria.
XAMPP version: 3.2/php 7.2
Operating System: Window 8.1 32bits

Re: Php mail error in beginner's application

Postby Nobbie » 18. December 2023 15:47

Chikwado wrote:Now, the php mail() function is not working. Why?


Because Thunderbird, Squirrelmail etc. are Mailclients in order to receive Emails.

For the mail()-function you need to setup a Mailserver instead (see php.ini), which does not receive Emails, but send them. You must either specify an SMTP Server in php.ini or specify a Program like "sendmail", which can send Emails. PHP cannot send Emails, it can only pass the credentials and arguments of mail()-function to the Server or Email Program.

Unfortunately, the SMTP configuration of PHP is very outdated and does not apply the option of configuring a Login (User, Password) for a SMTP Server. But nowadays, all SMTP Servers are protected via login, formerly (many years ago) SMTP where free and without login. You can only assign SMTP to localhost and create your own local SMTP server (using Mercury Mail). But this is a very sophisticated task. And it does not work mostly, as more or less all Email providers block Emails from private IPs due to SPAM problems.

Xampp delivers a fake sendmail.exe (see your installation), you can apply this program in php.ini as SendMail program. It comes with a configuration file sendmail.ini, there you can apply a known public SMTP Server for your Emails (like Google or GMX). Your Emails then are send via GMX or Google.

Sending Emails via PHP from your private PC is a sophisticated task. It does not work out of the box. Remember that you had to specify SMTP Servers and UserID, Password in Thunderbird as well in order to send Emails.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: Php mail error in beginner's application

Postby Chikwado » 19. December 2023 03:49

Thanks for reply
I have uncommented this line:
Code: Select all
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
   
in php.ini. Also edited sendmail.ini I have edited it as
Code: Select all
smtp_server=smtp.localhost
smtp_port=25
smtp_ssl=auto
error_logfile=error.log
auth_username=thunderbird@localhost
auth_password=thunder@bird&33

Still not able to send email in server.
Please what are the next settings that I should create?
Window8.1 32bits, Code:Block/mingw, web, server, network and latest wine.
User avatar
Chikwado
 
Posts: 38
Joined: 16. July 2014 13:44
Location: Abuja, Nigeria.
XAMPP version: 3.2/php 7.2
Operating System: Window 8.1 32bits

Re: Php mail error in beginner's application

Postby Nobbie » 19. December 2023 12:52

You applied localhost as SMTP server. But you did not install any SMTP server. That does not work. You should apply a known SMTP server, like you did in Thunderbird.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 204 guests