WordPress.org

Ready to get started?Download WordPress

Forums

wishlist/page content email (6 posts)

  1. leemustard
    Member
    Posted 1 year ago #

    Hey guys, Glad to be part of the WordPress community. First time using the forums.

    So my question is, Currently i have a wishlist i would like to fire off via email (similar to share to a friend) Basically the user adds a certain product(custom post type) to their wish-list, And once they on their wish list/account page they can share this to a friend. Now up intill here its pretty standard.

    The main thing is, How can use the get content (by id) of the particular page to fire off the page as is/content or html to the user? is this possible.

    Hope the question is clear enough,

    Just a note its not an e-commerce site.

  2. bcworkz
    Member
    Posted 1 year ago #

    Do you wish to share the single item or the entire wish list? Either way, the principle is the same, but accumulating the wish list content gets more involved. You will need a text field to get the email address to send to. Submitting that triggers the rest of this. You would then build the email message into a single long string. Use wp_mail() to send the message. By default, WP sends mail From: wordpress@yourdomain.com. You can change this and the associated name with filters. At the very least you should also use the $headers parameter to set the Reply-To: to the user's email. It's not documented precisely how to do this, so it may take some trial & error. Start with something like $headers[] = "Reply-To: $email"; where $email was set to the user's email address. There's also some special headers and content that needs to be sent for html mail content to be valid.

  3. leemustard
    Member
    Posted 1 year ago #

    maybe that wasnt clear enough, even if i could grab the page contents and send it to a form or email script and then foward it

  4. bcworkz
    Member
    Posted 1 year ago #

    I'm sorry, I still don't understand. Perhaps try listing each small step you want to take to achieve your goal? And which of those steps do you not know how to do?

  5. leemustard
    Member
    Posted 1 year ago #

    hey thanks for your response, basically the user visits the page and browses a selection of items, The user can either enquire which bring up a modal with a contact form and some details to be filled in the other option(only once logged in) say add to wishlist, so when the user goes to their profile/your wishlist page, there it displays their wishlist saved items. so from that page i would like to send off an email, sending the contents in html to a recipient , so it displays actively with links html etc

    http://i.imgur.com/Jl9e5XA.png
    http://i.imgur.com/OmeYylk.png
    so on the second screenshot i want to add email to a friend, but obviously sending the contents of that wishlist/content div to a email recipient

    Thanks for the assistance thus far

  6. bcworkz
    Member
    Posted 1 year ago #

    Thank you for the extra detail, I know it seems overkill, but it assures me I understand you correctly.

    You need to realize email clients vary greatly in their ability to properly render compliant HTML. It's important to send content that can fail gracefully, and keep it as basic as you can stand to begin with.

    I believe my first post's information is still valid, though perhaps not what you were expecting. And here's more. You can't simply grab the content and mail it due to the email rendering issues. But you will still want to grab selected content as it comes out of the loop. For instance, you don't want to email the remove button, but most everything else should be OK. I also doubt many email clients will grab external CSS files, so you will need to construct an email specific head section with inline CSS that you hope the mail client will use.

    I would also suggest dynamically building an identical page on you site so you can provide a link for the recipient to follow if their email fails to render properly.

    Here's an outline of code needed to implement this the way I see it. I'm surely forgetting many details, and there are surely other approaches.

    Alter the wishlist template

    - accumulate selected content from the loop into $content
    - add a send to friend form containing email field and submit button and hidden field containing $content. Also include a hidden nonce field so no one can leverage this for spamming.

    On form submit

    Confirm user is logged in and nonce is valid
    prepare for using the wp-mail() function
    - add filters so the From: field is from the user. Remove any existing filters if necessary.(this step is sort of optional but the default could confuse the recipient)
    - prepare the $headers parameter, including the user's email in the Reply-To: field and the proper content type header for html.
    - prepare the html content. Build a head section including proper html content meta and inline CSS. (If you page uses any javascript, email clients will ignore it, plan accordingly).
    -add a blank copy of the email wishlist page to the database in order to have a page id for the next step.
    - add in to the message content the body tag and link about what to do if the content is difficult to read.
    - add in to the message content something about $user wanted to share this wishlist with you, if you do not want to receive such information in the future contact $useremail.
    - add into the message content the page $content sent with the form data.
    - add into the message content some footer information about your site.
    - add into the message content the closing tags
    - update the blank copy of the email wishlist page in the database with the actual content.
    - prepare the $to parameter from the form field data
    - prepare the $subject parameter
    - do $result = wp_mail($to, $subject, $message, $headers );
    - restore original From: field filters if needed.
    - send page to user confirming the $result

    Done! :)

Topic Closed

This topic has been closed to new replies.

About this Topic