简体   繁体   中英

Use of mailtodisk / mailoutput in XAMPP for Linux

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 = me@example.com

; 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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM