Test mail() function of PHP on localhost with Windows 8.1
On Windows PHP needs additional configuration.
Especially the SMTP settings are relevant.
http://www.php.net/manual/en/mail.configuration.php
The emulator "test-mail-server-tool" listens on the specified port, normally 25 and writes the mail send there into a specific folder. It takes the place of a real SMTP server, in fact it's a dummy for testing purposes. If the mail is sent, it should be in the specified folder of "tmst".
Complete Walk-Through
- install "test-mail-server-tool"
- start the tool
- go to tray: set port 25 and folder for the email output
- create new php file with the source code from the send mail example below
- execute the php file (in your browser or on cli)
- go to the defined email output folder
- find a "*.eml" file with the content of your email
Basic PHP example for sending mail
<?php
$from = "sender@sender.com";
$headers = "From:" . $from;
echo mail ("receiver@receiver.com" ,"headline" , "text", $headers);
?>
PHP : send mail in localhost
It is configured to use localhost:25
for the mail server.
The error message says that it can't connect to localhost:25
.
Therefore you have two options:
- Install / Properly configure an SMTP server on localhost port 25
- Change the configuration to point to some other SMTP server that you can connect to
Send email from localhost running XAMMP in PHP using GMAIL mail server
Here's the link that gives me the answer:
[Install] the "fake sendmail for windows". If you are not using XAMPP you can download it here: http://glob.com.au/sendmail/sendmail.zip
[Modify] the php.ini file to use it (commented out the other lines):
[mail function]
; For Win32 only.
; SMTP = smtp.gmail.com
; smtp_port = 25
; For Win32 only.
; sendmail_from = <e-mail username>@gmail.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
(ignore the "Unix only" bit, since we actually are using sendmail)
You then have to configure the "sendmail.ini" file in the directory where sendmail was installed:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=<username>
auth_password=<password>
force_sender=<e-mail username>@gmail.com
To access a Gmail account protected by 2-factor verification, you will need to create an application-specific password. (source)
Related Topics
How to Trigger Xdebug Profiler for a Command Line PHP Script
How to Write to the Console from a Laravel Controller
How to Post a Large Amount of Data Within PHP Curl Without Memory Overhead
A Script to Change All Tables and Fields to the Utf-8-Bin Collation in MySQL
Using Xampp, How to Swap Out PHP 5.3 for PHP 5.2
Curl Error 60: Ssl Certificate Prblm: Unable to Get Local Issuer Certificate
Why Are Escape Characters Being Added to the Value of the Hidden Input
What Are the Differences of System(), Exec() and Shell_Exec() in PHP
Why Use PHP Oop Over Basic Functions and When
Check If String Is Just White Space
How to Block 100,000+ Individual Ip Addresses
Decoding Numeric HTML Entities via PHP
PHP "Pretty Print" JSON_Encode
How to Load a PHP File into a Variable
PHP How to Go One Level Up on Dirname(_File_)
Upload Video on Youtube Using Curl and API V3
How to Keep the Chinese or Other Foreign Language as They Are Instead of Converting Them into Codes