Use of mailtodisk / mailoutput in XAMPP for Linux
Asked Answered
P

2

5

Unlike in Windows, i'm having trouble to use the "mailtodisk" PHP option in Linux. Looks like it doesn't even exist.

In "php.ini", in the mail section, there is no reference to it:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=localhost
; http://php.net/smtp-port
smtp_port=25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header=On

; Log all mail() calls including the full path of the script, line #, to address and headers
mail.log ="/opt/lampp/logs/php_mail_log"

[SQL]

I can't see the "Mail" link in the localhost homepage, for test the default mail form, because it's with many crashes like this one:

Notice: Undefined variable: TEXT in /opt/lampp/htdocs/xampp/start.php on line 12

Obs: despite this errors in the localhost homepage, i'm running projects without a problem.

In fact, it doesn't seems to have a "Mail" link in the menu (i've searched the source code).

I don't know if this info helps in any way, but the file "sendmail.php" uses a file that doesn't exist in my system: /usr/sbin/sendmail.

The current version of XAMPP is: 1.8.3, and was recently updated.

Is it possible to use "mailtodisk" in XAMPP for Linux? If yes, what i need to do in my situation?

Phelips answered 15/10, 2013 at 23:41 Comment(1)
I'd say that linux brings all needed tools to deliver mails to the local harddrive, but this requires knowing how to configure a mailserver. Unless "mailtodisk" also comes as an executable for linux, it seems this feature is only available for Windows. The XAMPP guys should know more - have you asked for support there?Goop
M
10

It doesn't exist, but this is my mailtodisk script:

/opt/lampp/mailtodisk/mailtodisk:

#!/opt/lampp/bin/php
<?php
$input = file_get_contents('php://stdin');
$filename = '/opt/lampp/mailoutput/mail-' . gmdate('Ymd-Hi-s') . '.txt';
$retry = 0;
while(is_file($filename))
{
    $filename = '/opt/lampp/mailoutput/mail-' . gmdate('Ymd-Hi-s') . '-' . ++$retry . '.txt';
}
file_put_contents($filename, $input);

Your XAMPP installation might not be in the folder /opt/lampp, if it isn't, you'll need to edit the script (although it doesn't have to live in the XAMPP folder).

Make sure your mailtodisk script can be run by anybody (chmod 755 mailtodisk), and your mailoutput folder can be written to by anybody (chmod 777 mailoutput).

Then your php.ini file (/opt/lampp/etc/php.ini) should have:

sendmail_path=/opt/lampp/mailtodisk/mailtodisk

Any time you edit the php.ini file, you have to restart Apache.

Installing sendmail if you don't want to send the emails, is overkill.

Merle answered 13/4, 2014 at 20:52 Comment(1)
This is Genius. I've posted a Windows equivalent guide below which is based on your script (credited). Hope that's okay.Latish
L
3

Windows XAMPP users:

Extending Lee Kowalkowski's brilliant solution:

1. Create new file mailtodisk.php

I created the file in C:\xampp\mailtodisk - remember this for step 3

2. Paste Lee Kowalkowski's script (minor mods of path already done) into the file:

<?php
$input = file_get_contents('php://stdin');
$filename = '/xampp/mailoutput/mail-' . gmdate('Ymd-Hi-s') . '.txt';
$retry = 0;
while(is_file($filename))
{
    $filename = '/xampp/mailoutput/mail-' . gmdate('Ymd-Hi-s') . '-' . ++$retry . '.txt';
}
file_put_contents($filename, $input);
?>

Change $filename as needed. For me it's in the same drive so /xampp worked fine.

3. Open php.ini (usually in C:\xampp\php) and look for sendmail_path, comment existing one and paste the following:

sendmail_path="C:\xampp\php\php.exe C:\xampp\mailtodisk\mailtodisk.php"

Ensure php.exe path is correct and the path to mailtodisk.php from step 1.

Restart Apache and you're done.

Note, I use Thunderbird so instead of .txt (in step 2) I personally use .eml so I can view the email directly.

Latish answered 5/6, 2020 at 13:37 Comment(1)
I really like this answer but there is an arbitrary way of figuring out where php.exe is so the code will work across different PC's (e.g. relative solution vers absolute solution). I have an idea on how this could work to as solution for my issue #70121078 but it needs to be relative not absolute.Algebra

© 2022 - 2024 — McMap. All rights reserved.