Support » Plugin: WP Better Emails » [Plugin: WP Better Emails] Possible to add user preferences

  • Hi,

    I’ve been trying to add some user preferences, so registered users can choose if they want to receive html or plain text emails. I realise that the html email includes a plain text version anyway (one of the many reasons why this plugin is the best) but most of my users aren’t tech savvy and it would be easier for them to choose a preference in wordpress than configure their email client. Also I don’t think webmail clients have this option at all.

    I’ve been trying to read the ‘to’ address from wp_mail() to work out the user id and match it against a stored preference, but haven’t been having any luck.

    Anyone else got some ideas on this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Also, %blog_url% string replacement, doesn’t work for me. I have my wordpress install in a sub directory to the www root and %blog_url% is pointing to the wordpress url, not the site url, as set in general options.

    Make sense?

    Plugin Author hellonico


    Hi ChemicalSailor,

    Why allowing user to set their own email format preferences ? Email clients that don’t support HTML emails will automatically choose the text version. That’s what “multipart” is all about : letting the recipient software decide whether to display the HTML or text version.

    If you still want to deal with user preferences, you first need to add a “Prefered email format” to the user profile, here’s an easy way to achieve this (replacing text field with select) :

    I guess you already did that ?

    Then grab the preferences of the user with the email as you did, there’s a built-in function for this :
    $user = get_user_by_email($email)
    Get the user meta with the key assigned to identify the email format :
    $format = get_user_meta($user->ID, 'email_format', true)

    Now you can modify the behavior of email sending : sending HTML only, text only or both (multipart) with some conditions.

    The string replacement will be corrected in the next (coming soon) version of the plugin.

    Hey ArtyShow

    Thanks for the reply. I understand about multipart emails. Unfortunately my users don’t. I know you can select a preference in mail clients whether to show html or plain text emails, but again my users don’t. I’m thinking that from an ease of use perspective it’d be easier for them to set that preference in there WordPress profile. Certainly a lot easier to educate users that way.

    As you guessed I’ve got as far as setting up the options form and retrieving said options. The problem I have is in mapping that option to the email being sent. As far as I can tell the plugin hooks into PHPMailer, which is only passed $to, $message, $headers and $attachments from wp_mail(). To make the plain text preference work, I need to identify the $to variable and match that to the user profile, but at the moment I can’t get the content of the $to field.

    I think the $to variable in the PHPMailer class is private, so can’t be accessed there. I had a go at filtering wp_mail but didn’t get very far. What would be really nice is if the plugin could take the userid of recipient as an input, but that would require re-writing the wp_mail function, so again I don’t think really feasible. Right now I’m just looking for some other ideas to try, as you obviously know the plugin inside out you’re probably my best bet.

    I already patched the php for the string replacement. I also added a string replacement for %subject% in the wpbe_send_html function, as I wanted to include the email subject in the email body. I would link to the patched file for you, but can’t access my server at the moment! I’d also suggest creating a new filter in the string replacement function, so users can define their own replacements.

    Thanks again for your help.

    I’d say: let them chose between plain text and HTML and send them HTMl anyway…
    they won’t notice 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WP Better Emails] Possible to add user preferences’ is closed to new replies.