3

I'm using what I learned over at https://stackoverflow.com/a/3176517/ to route mail()-commands in PHP on my local machine to a file. From the php.ini:

sendmail_path ='tee /testmail/mail.txt'

But when I add an additional_parameter (-fwebmaster@example.com) it generates an addtional file named -fwebmaster@example.com with the content of the mail in the current folder.

A complete example:

$ cat | php -d sendmail_path='tee /testmail/mail.txt'
<?php
mail('test@example.com', 'subject', 'body', '', '-fwebmaster@example.com');
?>
To: test@example.com
Subject: subject


body

The last five lines are written to /testmail/mail.txt and and newly created -fwebmaster@example.com.

It seems that the -f-parameter gets forwarded to the tee-command. Is there a way to prevent that?

(Using cat results in an error and PHP returns false.)

Community
  • 1
  • 1
Steffen Wenzel
  • 1,091
  • 11
  • 16

1 Answers1

1

You can ignore any additional arguments passed from php by wrapping your command in a shell script:

pseudo_sendmail

#!/usr/bin/env bash
tee /testmail/mail.txt

PHP config:

sendmail_path ='/path/to/pseudo_sendmail'
Leon
  • 31,443
  • 4
  • 72
  • 97
  • Just want I wanted. This means I can even write `#!/usr/bin/env bash tee /testmail/mail.txt cp /testmail/mail.txt /testmail/mail.eml` to simultaneously create a "real" email for easier previewing. – Steffen Wenzel Oct 12 '16 at 17:50