Solution to add -f parameter to send email

  1. loru88

    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: 6 years ago #
  2. 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: 6 years ago #
  3. loru88

    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: 6 years ago #
  4. 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.


    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:

    So the plugins I mentioned?


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

    Posted: 6 years ago #
  5. loru88

    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: 6 years ago #
  6. Oleg Komarovskyi

    Thank you loru88
    Helped me alot! :)

    Posted: 3 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    1 Vote
  • Status

    This idea is under consideration