• Resolved Frank

    (@t-mug)


    Hi support,

    if you would use the “phpmailer_init” hook of WordPress’ wp_mail() function (instead of defining your own method) then dev’s had the chance to influence mail headers as well. For instance if I want to disable the XMailer variable of the PHPmailer class, I would have to hack your plugin, right? Because I cannot reach your instantiated PHPmailer class. Not so helpful and WordPress does a better job regarding to offer other plugins possibilities of change, so why not using wp_mail()?

    Also modifications like AddCustomHeader(‘Precedence’, “bulk”) would be nice to run through a filter since this is not on the wishlist in every case.

    Thanks, if you could agree.
    The best,
    Frank

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Tribulant Software

    (@contrid)

    @t-mug

    We are not defining a method, where do you see that?

    The plugin has 3 possible mail types built into it:

    • Local mail server (uses wp_mail)
    • SMTP (uses phpMailer included with WordPress)
    • API (uses SDKs from various mail relays like SendGrid, MailGun, etc.)

    The plugin uses wp_mail() when local mail server is selected under Newsletters > Configuration > General > General Mail Settings. For SMTP and API it uses it’s own code.

    And for local mail server using wp_mail() it does hook to phpmailer_init filter hook to add headers, etc. You can then hook to phpmailer_init in your own turn at a higher priority to add headers as you wish.

    Are you using local mail server, SMTP or API? For SMTP, the plugin uses the built in phpMailer class distributed with WordPress. We can add an action/filter hook for you to modify the $phpmailer object and use it before the sending occurs? Would that be useful?

    Thread Starter Frank

    (@t-mug)

    Hi,
    thanks for your response!

    First, yes I use the SMTP variant of sending email. And for this you provide the wpMailPlugin class, which defines the method execute_mail(). There you do not use wp_mail() and this is my problem. Even including the WP phpmailer class circumvents to took into the process if you want to change e.g. headers.

    For SMTP, the plugin uses the built in phpMailer class distributed with WordPress. We can add an action/filter hook for you to modify the $phpmailer object and use it before the sending occurs? Would that be useful?

    Yes, that would be very useful and is exactly what WordPress’ phpmailer_init hook does when using wp_mail(). But for your plugin’s use of AddCustomHeader in execute_mail(), as mentioned in my initial post, it would not help … To have complete access to headers, those which are added in a hard way by the plugin should run through a filter as well, ideally. To run clearCustomHeaders() on the mailer object and build headers up again is kind of fault-prone …

    Anyway, as suggested by you: to have access to the mailer object would help a lot.

    Thanks for your quick resonse, very appreciated!

    The best,
    Frank

    Plugin Author Tribulant Software

    (@contrid)

    @t-mug

    You’re welcome and thanks for your response.

    Yes, for SMTP, the plugin doesn’t use wp_mail() but rather uses the phpMailer class and it’s own code. There are several reasons for this.

    We’ll add filter hooks so that you can access the $phpmailer object accordingly. If you need a development version and don’t want to wait for an update, we can send it to you asap, please open a ticket for that: https://tribulant.com/support/

    Thread Starter Frank

    (@t-mug)

    Please have a short look at this:

    
    // For all unconditional settings on the mailer object.
    $set_headers = array(
         array( 'CharSet',    true ),
         array( 'MailFrom',   true ),
         array( 'Precedence', true ),
         ...
    );
    $header_tasks = apply_filters( 'newsletter_mailer_headers', $set_headers );
    

    and then, instead of
    $phpmailer -> AddCustomHeader('Precedence', "bulk");
    you could do this

    if( $header_tasks['Precedence'] )
         $phpmailer -> AddCustomHeader('Precedence', "bulk");

    Or any other way that does not force settings into mail headers. Both wp_mail() and class PHPMailer allow to prevent a setting to be applied. You do not, unfortunately. Even not when providing the mailer object via hook only. That helps, no question! But if I don’t want the Precedence header line, I have to reinvent the wheel of mail_excute() after it has reinvented the wheel of wp_mail() ?? because the mailer object has to be cleared over and over again.

    Do you see, what I mean?

    Thanks again!

    All the best wishes,
    Frank

    Thread Starter Frank

    (@t-mug)

    I meant:

    array(
         'CharSet' => true,
         ...
    )

    but you’ve got the idea.

    The “Precedence: bulk” header should always be there by default, and the filter should be to opt out (not the other way around). That way users who wish to remove it can still do so.

    All major email providers eg. Gmail, Hotmail, Yahoo etc. expect this header to be present as part of mailing list best practice. If their system detects multiple incoming messages with the same content and lacking the bulk header, it often trips spam filters. That’s why all mailing list providers like Mailchimp, Constant Contact, Aweber etc. include this header.

    • This reply was modified 7 years, 1 month ago by menathor.
    Thread Starter Frank

    (@t-mug)

    1.) In the Code above the boolean is set to TRUE, so my suggestion was to keep it in place anyway. To remove it, I would have to code a filter.

    2.) From RFC2076:

    Non-standard, controversial, discouraged. Sometimes used as a priority value which can influence transmission speed and delivery. Common values are “bulk” and “first-class”. Other uses is to control automatic replies and to control return-of-content facilities, and to stop mailing list loops.”

    So no, Sir.
    > all mailing list providers like …
    This is almost phantasy. Yes, maybe Mailchimp does, but it is non-standard. Leaders like Infusionsoft and many others don’t use it, even Google and Facebook mass mailings are not using it.

    So there should be the choice to remove it.

    • This reply was modified 7 years, 1 month ago by Frank.
    Plugin Author Tribulant Software

    (@contrid)

    @menathor and @t-mug

    Thank you for all the great feedback, we are currently working on this.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Use wp_mail() instead of reinventing the wheel’ is closed to new replies.