Sendmail stub for PHP and PHP


Each time setting up a local web server, I come across a question about a stub for Sendmail.

There is an excellent solution for Windows: fake sendmail for windows (sendmail.exe)
There is an article on the hub about this solution: PHP mail for Windows /
Another solution for Windows: Test Mail Server Tool
There is also an article for Linuxoids: Sendmail-stub for Linux / 49665 /

Personally, I liked the solution in pure PHP more, which will be described later.

The peculiarity of this solution is that its configuration is minimal, you can even do without the file itself, unless of course you need to know the contents of the message. In my opinion, such a method is worth what other PHP developers would know about it.

The question is what is your priority as a developer, your needs are a stub, as well as your level of knowledge and skills.

From the pros:
  • Lack of third-party services
  • Cross-platform solution for OS on which PHP is installed
  • Minimum stub file size
  • Minimum setting
  • All stub logic is editable in PHP.
  • Save message to file

Of the minuses:
  • No forwarding to a real mailbox
  • Lack of convenient access to sent messages

List of stub arguments and features:
  • --dir <Folder path> - Folder for files
  • --file <file name> - Save each message in a specific shared file
  • --prepend - Add a new message at the beginning of the shared file
  • --open - Automatically open message file in Notepad

Parameters for the PHP.INI file:

[mail function]
;SMTP = localhost
;smtp_port = 25
;sendmail_from =
sendmail_path = "php.exe C:\sendmail.php --dir C:\mail --open"

If the path to php.exe is written in PATH, then you can omit it in PHP.INI otherwise it is advisable to change php.exe to <Path to the folder with PHP> \ php.exe

sendmail_path = "C:\server\bin\php\php.exe C:\sendmail.php --dir C:\mail --open"

On Linux, you can immediately specify the path to the file, without forgetting to first make it runable: chmod 755 sendmail.php
sendmail_path = "/home/someuser/sendmail.php --dir /tmp/mail"

The sendmail.php script itself:

#!/usr/bin/env php

Как я и обещал, есть также возможность обойтись совсем без файла.

sendmail_path = "C:\server\bin\php\php.exe -r 'echo 1;'"

Либо использовать упрощённый вариант решения

sendmail_path = "C:\server\bin\php\php.exe C:\sendmail.php"


#!/usr/bin/env php

Буду рад, если Вам это будет полезным.

Also popular now: