Skip to:
Content
Pages
Categories
Search
Top
Bottom

Windows (Apache2/PHP/5.2.6/MySQL5.1.30)

  • I just installed bbPress on a Windows XP system without incident.

    Went in very easily.

    However, the PHP ‘mail()’ function on Windows uses an MTA.

    That is, it communicates directly with an SMTP server rather than using any intervening software.

    This means that the ‘From:’ header format must be very simple:

    ‘From: user@domain’

    instead of:

    ‘From: “Name of bbPress system” <user@domain>’

    Otherwise, the SMTP server returns an error and does not send a message.

    An easy change can be made to bb-includes/pluggable.php::bb_Mail().

    Change:

    $headers[] = ‘From: “‘ . bb_get_option(‘name’) . ‘” <‘ . $from . ‘>’;

    to:

    $headers[] = ‘From: ‘. $from;

    The change will work with all systems or it can be placed under a

    Windows-specific switch.

Viewing 11 replies - 1 through 11 (of 11 total)

  • chrishajer
    Participant

    @chrishajer

    Good feedback on that system.

    Better than modifying a core file (which won’t survive an upgrade) is to use a plugin that allows you to use an SMTP server:

    https://bbpress.org/plugins/topic/smtp-mailer-for-bbpress/

    There are also threads in the forum about using Swift Mailer, IIRC.

    Well, I suppose that would solve the problem, but ‘bb_mail()’ already calls PHP ‘mail()’ which transparently handles SMTP. No plugin required.

    Yes, I know this requires a change to the core, but it is trivial and transparent.


    chrishajer
    Participant

    @chrishajer

    The only concern I have with modifying a core file is that the modification might be forgotten about, then when you upgrade (3 months, 6 months, a year or more later), something stops working and you’re left wondering why. I know you would never have that trouble, but I would caution anyone else from modifying core files and stick to using plugins to override functions that appear in pluggable.php. Upgrades are so much easier when you don’t need to keep track of what you modified in the core.

    Thanks for the Windows feedback in any case.


    chrishajer
    Participant

    @chrishajer

    Re-reading your initial post, I recall this was mentioned in the forums here (at least) once before.

    https://bbpress.org/forums/topic/email-wont-send-from-anyhting

    https://bbpress.org/forums/topic/user-registration

    I was not referring to me modifying the core, but rather suggesting that the developers modify it for a future release of bbPress.

    SMTP is a major mail API. It can be handled transparently by bbPress with the existing underlying PHP support of the ‘mail()’ function. Seems like a one line (and transparent to existing systems) change in bbPress would be preferable to requiring bbPress admins to discover the issue, debug it, and then find and install a plugin. It would have also prevented me (and judging from the forum topics, others) from spending our (and your) time on the issue as well. Perhaps I am missing something about the development and distribution of bbPress, but using a plugin for a 1 line change is putting a sledgehammer to a tack. Especially since a system presumably built for *nix systems goes into a Windows environment (and rather an unusual one at that; IIS being generally preferred to Apache in that world) rather well. Just my 2c worth.


    Sam Bauers
    Participant

    @sambauers

    PHP mail() only uses SMTP when PHP has been directed to use an MTA by default like in your case. There are plenty of situations where this isn’t the case, like on a lot of shared hosting services. In these cases the only way to send mail is to programmatically connect to an SMTP server. This is possible in 1.0-alpha versions using the plugin that chrishajer pointed out.

    I wish it was as easy as changing that one line, believe me. Also, if your MTA is not accepting that very standard form of email address then it is really a config issue at the MTA. There is no reason it should be rejecting an RFC compliant email address like that one.

    I see. So the preferred solution is to route anyone who wishes to use SMTP with bbPress, and is not happy with the default PHP behaviour, to use the SMTP plugin. Fair enough.

    There is another solution for Windows SMTP systems for those who control PHP; live with setting ‘sendmail_from’ server-wide in php.ini. This overrides the value passed to the mail() function ‘From:’ header argument for use with the SMTP ‘MAIL FROM:’ command (where the problem lies), but retains that value for use with the mail message body ‘From:’ header (where a complete textual name may be used).

    BTW, the reason that the (SMTP) MTA on Windows rejects the email address is not due to the MTA, but due to PHP on Windows:

    http://www.php.net/manual/en/function.mail.php

    A long-standing discussion is here:

    http://bugs.php.net/bug.php?id=28038

    The current value for the PHP mail() function ‘From:’ header (“User name” <uname@domain.com>”) is an RFC2822 compliant format suitable for parsing by a library (like PHP mail()) which *should* generate separate strings for SMTP (the ‘MAIL FROM:’ command, which must be RFC2821 compliant) and the message body (the ‘From:’ header field which can be RFC2822 compliant). RFC2821 format (user@domain.com or <user@domain.com>) differs from RFC2822 format. PHP mail() on Windows does not do this translation.


    Sam Bauers
    Participant

    @sambauers

    @iservers

    Well, that’s different… :)

    But I just realised you are using bbPress 0.9 – the bb_mail() function has been replaced in 1.0-alpha with one more like wp_mail() in WordPress.

    It was replaced in part because people had problems sending from Windows environments. You have probably just pinpointed the cause of that. Just a few months too late unfortunately!

    For now I would just hack the core of 0.9 if I were you – it is unlikely to see any more updates. The replacement function in 1.0 should take care of this, although I would appreciate it if you could test 1.0-alpha for the same problem if you have some time.

    1.0-alpha has the same issue, despite the heroic attempts made to scrub the mail headers. I would have done this sooner but I tend to avoid alphas, especially when I am new to a system.

    Let me try to summarize again, hopefully more clearly, for future readers. The PHP mail() function (in Windows, and without ‘sendmail_from’ being set in php.ini) overloads the meaning of the ‘From:’ header argument to include the SMTP ‘MAIL FROM:’ command value (the one sent over the socket to the SMTP server) in addition to the normal meaning of the header: the email message body ‘From:’ header (the one that most people think of — the one displayed in the headers of messages in your email client that frequently includes a textual name as well as an email address).

    Not only is the nature of this issue obscure (two meanings for seemingly the same header), but it is further muddied by the behaviour of PHP mail() on different platforms (Windows and non-Windows) and within Windows itself (with and without ‘sendmail_from’ being set in php.ini). The obscure and incomplete Note in the PHP mail() documentation does not help matters either.

    So, without either PHP mail() changing (seems unlikely as this issue has existed for years) or without specific knowledge of Windows being added to clients (cough), the solutions are: 1) if PHP is under your control, set the ‘sendmail_from’ variable (server-wide) in php.ini (and it will be used as the value for the SMTP ‘MAIL FROM:’ command), or 2) if the client supports SMTP directly (bbPress does so with a plugin), use it, specifying two values for the ‘From’ header (the SMTP value must be a simple email address such as “me@example.com” while the other value may include a textual name and an email address, such as “Myself <me@example.com>”.


    Sam Bauers
    Participant

    @sambauers

    OK, so should we manually set “sendmail_from”…

    ini_set( 'sendmail_from', 'me@example.com' );

    Which only affects Windows servers anyway I believe.

    Yes. What was I thinking?!? Unlike php.ini, the value can be specified in an optional bbPress configuration field (visible if SMTP is in use?) and set from a script, handling shared hosting environments as well.

    Elegant solution. No plugin required.

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar