Problems sending email through XAMPP localhost

I have problem sending email using mail() function through XAMPP using sendmail (I know that there is PHPmailer, but please do not suggest using it).

Here is the PHP code:

<?php
   $to_email = "receiver@gmail.com";
   $subject = "XAMPP Test";
   $body = "XAMPP Test";
   $headers = "From: sender";
 
   if ( mail($to_email, $subject, $body, $headers)) {
      echo("Email successfully sent to $to_email...");
   } else {
      echo("Email sending failed...");
   }
?>

In php.ini I have set:

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = ********@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

‘extension=php_openssl.dll’ is by default uncommented.

In sendmail.ini:

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
error_logfile=error.log

auth_username=********@gmail.com
auth_password=********
force_sender=********@gmail.com

On my desktop PC there is no problem with this configuration, on my notebook, there is. Is it something related to the Apache server port, because on the PC there is the default port 80, and on my notebook it is 8080 because 80 is already taken. I also have disabled every protection such as firewall and antivirus but sending email is still a puzzle.

Is it possible for a solution here?

P.S. No error logging at all.

Thanks.

Is your xampp install on your laptop in C:\xampp?

Is this just for development testing purposes or are you actually trying to use it for production?

Yes.

For development testing purposes.

If you want to use the mail() function with XAMPP, you’ll have to get Mercury up and running.

Why is that, out of interest? Virtually every “PHP won’t send email reliably” problem I’ve seen on here has had a response of “use something like PHPMailer, it’s far better”. Just wondered why you are ruling it out.

1 Like

I didn’t like to mention it, but setting up PHPMailer (or SwiftMailer) is probably a lot easier than setting up a mail server on localhost.

First suggestion, use Laragon instead of XAMPP. It is better and includes a mail catching utility by default. If you are staying with XAMPP, you can install PaperCut which is a standalone SMTP email catcher. Problem Solved.

Thanks to all for your valuable suggestions, but let’s pretend that I need a solution to my question. If someone can show me guidance on what and where to check towards solving this strange problem, that would be much more appreciated.

On my PC I have never had the need to use it. Why would be this necessary on my notebook, any suggestions? Maybe some background services conflicting?

Thanks

No, no, I am not ruling it out, indeed I support the usage of PHPMailer, but as I already stated, I need a solution to my original question, because, to be honest, I somehow feel uncomfortable while these strange occurrences are unresolved :exploding_head:. I am not a nut

I don’t know what you have running on either your desktop or laptop, but you need a mail server to use the mail() function. You could use something else, I imagine, but Mercury comes as part of XAMPP which is why I suggested that.

What operating systems? Are they both WIndows machines?

I’m guessing the are, as the paths start with "c:".

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.