Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP mail() function triggers 'missing recipient' message #3

Closed
geerlingguy opened this issue Jun 2, 2015 · 8 comments
Closed

PHP mail() function triggers 'missing recipient' message #3

geerlingguy opened this issue Jun 2, 2015 · 8 comments

Comments

@geerlingguy
Copy link

I kept digging deeper and deeper (I really want to use mhsendmail instead of sSMTP for my Drupal dev environments!), and found that PHP's mail() function is the culprit here, in terms of how it uses sendmail...

To reproduce, install PHP on a server, set the sendmail_path ini directive to the path to the mhsendmail binary, then create a script somewhere with the following test:

<?php
$to = 'nobody@example.com';
$subject = 'Test';
$message = 'Test message.';
$headers = 'From: webmaster@example.com' . "\r\n" .
  'Reply-To: webmaster@example.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();
$result = mail($to, $subject, $message, $headers);
var_dump($result);
?>

If you run the script by accessing it through a webserver, check the webserver's error logs; you should get a message missing recipient, from mhsendmail.

The problem is that it seems mhsendmail is expecting the recipient as one of the command line args, but PHP's mail() function passes the recipient as a line in the header ('To: [recipient]'). See php-src: https://github.com/php/php-src/blob/fc33f52d8c25997dd0711de3e07d0dc260a18c11/ext/standard/mail.c#L356-L361

I think if you can make it so mhsendmail accepts the To address as the first line of stdin, it might work...

@ian-kent
Copy link
Member

ian-kent commented Jun 5, 2015

Thanks @geerlingguy, I'll have a look

@stucki
Copy link

stucki commented Aug 5, 2015

I can confirm this problem.

The simple workaround is to provide a dummy email address in PHPs sendmail_path:

sendmail_path = "/usr/local/sbin/mhsendmail test@test.com"

The recipient will be overwritten when the "To:" header is added by PHPs mail() function.

@ian-kent
Copy link
Member

ian-kent commented Aug 5, 2015

Thanks, and sorry, haven't had time to look at it yet, I'll get a fix in asap!

@ashleyhindle
Copy link

👍

ian-kent added a commit that referenced this issue Oct 6, 2015
Parse "To" lines in the message itself. Fixes #3
@stucki
Copy link

stucki commented Oct 6, 2015

Thanks!

@geerlingguy
Copy link
Author

Looks like this works, but could you tag a new release so we can download the binary for use in other projects? :)

@domodwyer
Copy link

+1 on the new binaries, I pull them using Chef for our development environment and just got bit by this!

@iefbr14
Copy link
Contributor

iefbr14 commented Nov 20, 2015

The re for find To: doesn't work correctly
Here is a fix.

re := regexp.MustCompile("(?im)^To: (.*)\r*$")

iefbr14 added a commit to iefbr14/mhsendmail that referenced this issue Nov 20, 2015
mailhog#3

The re for find To: doesn't work correctly
Here is a fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants