Marketpress Email Delivery address comes from Multisite and not actual site

Greetings All :slight_smile:

the scenario is on a WP MS V3.1.2 using Market Press V2.0.5, the MultiSite Master Domain Name is for example mastersite.com and a user site named usersite.com (a real domain) using Market Press.

A purchaser goes to usersite.com or usersite.mastersite.com and makes a purchase - the emails the user receives with order information, confirmation etc. shows that it comes from mastersite.com

Even if the email showed the non mapped domain name i.e. usersite.mastersite.com would be better then just saying it was from mastersite.com

I can see now that if a purchase problem arises people writing and going after mastersite.com and not usersite.com or usersite.mastersite.com whom may be in an actual position to do something about it.

This of course is irrelevant for those not allowing other people then just the master site to use Market Press - but you can also quickly see how this could become a nightmare for the administrator of the Master Multi Site Installation.

Joe :slight_smile:

  • aecnu

    Greetings Phil :slight_smile:

    now that is a very interesting concept and possibility that this is because the admin email is the same for both sites - which is absolutely true in this case because it is our own separate domain within the WP installation therefore the admin's are the same with the same email address - though the email address itself is not within the WP installation domains i.e. the email address is abcd.org while the WP addresses are fghij.com and xyz.com

    Therefore since the admins have the same address and they may be causing this anomaly, if we want to call it such, I would consider this ticket closed for this reason and wait until I have a user not connected with us indicate there is a problem :slight_smile: and deal with it at that time.

    Thank you Phil for this perspective brought on by your comment :slight_smile:

    Joe :slight_smile:

  • Timothy Bowers

    Hey Phil - Sorry not been around much over the last week or so :'-( Had a number of things on.

    I had an issue where a user was reporting the same thing and didn't like the fact his customer appeared to get e-mails from our main site.

    I looked at all uses of the wp_mail() function and found 4 in MarketPress, all located in the /marketpress/marketpress.php file. All 4 don't send any headers and so leave it to WordPress to handle with its defaults (wordpress@).

    I've adjusted mine to now include headers which send the From address for all mails.

    The wp_mail instances will look like:

    wp_mail($order->mp_shipping_info['email'], $subject, $msg);

    Note that only 3 arguments are passed, the 4th would be headers and the 5th is attachments.

    Another issue to consider is the fact that BuddyPress also tries to be the big chief here creating a noreply@ address and the networks name. So I had to also remove those filters:

    remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
    remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');

    If you remove these filters then you might want to add headers to all 4 instances of wp_mail() to ensure emails don't arrive to your clients with wordpress@, saves confusion and branding for you then. :slight_smile:

  • aecnu

    Greetings Timothy and Phil :slight_smile:

    well this ticket should be re-opened so that the developers can put the permanent fix on this issue with the fix to be possibly included in the very next update.

    Meanwhile Timothy if you do not mind telling please - what exactly did you do to fix this anomaly?

    or did you include the fix and I am completely missing the boat on this one? .... lol

    I seen that you included in your post how to identify the emailing line, but you did not include details of fixing it.

    Unfortunately on the World Stage I specialize in Networks and Linux Servers .... not a programmer :slight_frown:

    Joe :slight_smile:

  • Timothy Bowers

    Hi Joe. Sorry, you are right I was not clearer enough. :-s

    If you running BuddyPress then this will over rule the e-mails sent out giving it a noreply@yourdomain.com. To remove the BP filters add the following to your /marketpress/marketpress.php file:

    remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' );
    remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter');

    You can add this anywhere really as long as it removes the filters so you can use your own headers in all instances of wp_mail().

    To be precise though you can have these filters removed only when needed, so the first instance where wp_mail appears is in the following function:

    function order_notification($order_id) {

    And looks like this:

    wp_mail($order->mp_shipping_info['email'], $subject, $msg);

    The second in this function looks like this:

    wp_mail(get_option('admin_email'), $subject, $msg);

    The first one is what is sent to the customer, the second is the admin notification.

    So we want to pass it some information for the headers, there are various ways but whilst testing I like to seperate code up to make it clear in my mind so this was my first version:

    $blogname = get_bloginfo('name');
    
      $blogmail = get_option('admin_email');
    
     $headers = "From: ". $blogname . " <" . $blogmail . "> "."\r\n";

    I'm assigning the blog name to $blogname and the admin email to $blogmail, I'm then assigning these two variables into one string and assigning the data to the $headers variable.

    We then need to pass the headers to the mail function, this function takes 5 arguments:

    <?php wp_mail( $to, $subject, $message, $headers, $attachments ); ?>

    $to = Who it is being sent to
    $subject = The subject of the mail
    $message = The body of the mail (content)
    $headers = From and reply to addresses, you can also include mail client details as well if you wanted to.
    $attachments = For attaching files which we are not doing.

    With arguments, you need to supply them in order, the wp_mail functions in the marketpress.php already have the first 3 arguements, so we just need to supply the headers and we do that like:

    So those two I quoted above no look like this:

    wp_mail($order->mp_shipping_info['email'], $subject, $msg, $headers);

    The second in this function now looks like this:

    wp_mail(get_option('admin_email'), $subject, $msg, $headers);

    Don't forget to assign the variables as I covered above:

    $blogname = get_bloginfo('name');
    
      $blogmail = get_option('admin_email');
    
     $headers = "From: ". $blogname . " <" . $blogmail . "> "."\r\n";

    Same process for the other uses of wp_mail() which can be found in the functions:

    function order_shipped_notification($order_id) {

    And

    function low_stock_notification($product_id, $variation, $stock) {

    If you remove buddypress then mail from address will default back to wordpress@ instead of noreply until you define the headers hence why I edit the other admin mails which your client/site owner will receive.

    Hope this helps. :slight_smile:

  • Timothy Bowers

    Thanks Phil. :slight_smile:

    I like the idea of a custom from address so you could us a billing address which could be different from the admin e-mail address.

    Buddypress caused me issue with other plugins when sending mail.

    Just to backtrack on my post a little:

    You can add this anywhere really as long as it removes the filters so you can use your own headers in all instances of wp_mail().

    To be precise though you can have these filters removed only when needed, so the first instance where wp_mail appears is in the following function:

    I realise I never finished saying what I wanted. lol

    I personally would include the filter removal only in the functions where wp_mail() is being used, thus the filters are definitely only applied when that function is called and not whenever the file marketpress.php is being included somewhere.

  • aecnu

    Holy Smokes Tim! Thank you .... and that is some coding to be done there ..... I see that Aaron is already on this and hopefully he will have it incorporated and available soon :slight_smile:

    I am definitely not a coder but a Network/Server type .... Fortunately I can follow instructions but this makes my head spin at first glance .... lol

    Now I cannot decide on whether to wait on Aaron or give this a shot .... lol

    Joe :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.