WordPress.org

Ready to get started?Download WordPress

Ideas

Solution to add -f parameter to send email

  1. loru88
    Member

    Hi
    I recently had a problem with Tophost hosting and WP Contact Form 7
    the problem is from Tophost, it blocks every mail sent without that parameter.
    I have resolved by hacking the wordpress core:
    open wp-includes/class-phpmailer.php
    search the line with
    public $Sender = '';
    at about line 97, this is an empty string, put your email instead and save the changement.
    now you will receive email, phpmailer automatically set the -f parameter when this string is not empty

    Would be great to put a hook filter to control the value of that variable because at every wordpress upgrade you have to rewrite your email
    so I propose to do add a filter here, or maybe a constant to define in wp-config.php

    Posted: 8 months ago #
  2. Ipstenu (Mika Epstein)
    Administrator

    You can use other plugins to edit this. Actually you can tell Contact Form Seven to use YOUR email all the time when you send, and that should fix it since it will define an email on send.

    We NEVER suggest ANYONE edit core. And since I presume WP was sending out registration info emails (like when you got WP set up), it's just the plugin here causing the problem.

    Posted: 8 months ago #
  3. loru88
    Member

    I think you have misunderstood the concept!
    Some hosting service, like Tophost as I mentioned, doesn't permit to send email if you don't set this parameter.
    A temporary way to solve this problem, independently from Contact Form 7 or similar plugins, is to do this hack. The variable I suggest to modify is not used by any plugin to identify the email's sender, it's just a phpmailer class parameter!

    As I perfectly know to not edit core files, my idea, to apply in official future WordPress versions, is to put over there, an hook to set this parameter and help people have this kind of problem.

    Posted: 8 months ago #
  4. Ipstenu (Mika Epstein)
    Administrator

    You specifically mentioned Contact Form 7. Are you actually trying to say that WP can send out no emails? Not even registration alerts and comment alerts? That's a different bug than "A plugin isn't working" you understand :)

    now you will receive email, phpmailer automatically set the -f parameter when this string is not empty

    Right, what I was saying is that if you use a plugin or a function to change public $Sender = ''; then it'll work :) WordPress can override that.

    http://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-phpmailer.php#L92

    That's setting the default to blank. The job of the plugins, including Contact-Form 7, is to override that and set the sender as the person who's filling in the form. Now, in actuality, many hosts don't let you send email if you're not using an email that matches the domain (that is if my domain is example.com and I try to send email from gmail.com, it won't work).

    For example DreamHost does exactly that, and suggests you use a plugin:
    http://wordpress.org/support/topic/contact-form-7-not-sending-emails-no-confirmation-no-error?replies=48

    So the plugins I mentioned?

    http://wordpress.org/plugins/tags/wp-phpmailer
    http://wordpress.org/plugins/tags/phpmailer

    It's always a good idea to ask your host "Do you have restrictions on PHPMailer?" Because WordPress is using the default one.

    Posted: 8 months ago #
  5. loru88
    Member

    ok, I found I better solution, it doesn't need to hack the core:

    add_action('phpmailer_init', function($phpmailer){
    $phpmailer->Sender = $phpmailer->From;
    });

    It set the property Sender as same as the From email in the object of class PHPMailer.
    The property From is filled with the email address of the person who's filling in the form, but the property Sender is left blank from the wp_mail() function and at least also Contact Form 7 leave it blank.

    This property is needed to set the Return-Path in the email header with the -f parameter as mentioned in the documentation: http://php.net/manual/en/function.mail.php

    My fault is to have post this in the Ideas area but this is a tecnical solution, sorry

    Posted: 8 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    0 Votes
  • Status

    This idea is under consideration