• Hi does anybody have any idea on how to stop using the current wp_mail function and use this instead. I have no real idea to go around this?
    Assuming wordpress is installed at the root directory and your website is called thesite.com
    You go to https://www.thesite.com
    You log in to wordpress,
    You then go to https://www.thesite.com/mail
    This is NOT a wordpress page, it sees that you are logged in and then shows e-mails which have been sent to you.

    == When function is called to send e-mail ==

    So the wp_mail function needs to

    From $to find Real Name in UserTable
    From $from remove everything from and including @

    Make sure the following colums in the USerTable are set:
    EMAIL_FROM, EMAIL_SUBJECT, EMAIL_MESSAGE, EMAIL_HEADERS, EMAIL_ATTACHMENT_LOCATION.
    Make sure arrays are set in above colums, if not create new array for each.

    If array already exists:

    get value of EMAIL_FROM assign to $from-array
    get value of EMAIL_SUBJECT assign to $subject-array
    etc

    Then
    with the new message which needs to be added,
    $from-array = $from-array adding $from
    $subject-array = $subject-array adding $subject
    etc

    Then
    Post values back into database

    == On The /mail page ==
    Find out the user ID of the wordpress user currently logged in.

    get value of EMAIL_FROM assign to $from-array
    etc

    Then

    echo H1 These are you e-mails

    Then while there are more messages not yet printed

    echo H2 Subject H3 FROM
    echo p B – ATTACHMENT LOCATION DOWNLOAD LINK
    echo p B – EMAIL HEADERS
    echo p MESSAGE

    then if non left
    finish

Viewing 15 replies - 1 through 15 (of 16 total)
  • This is NOT a wordpress page, it sees that you are logged in and then shows e-mails which have been sent to you.

    Just so you know, that sounds like a huge contradiction to me (if the page isn’t part of WordPress, it can’t leverage the functions within WordPress that would verify your logged in identity)– but I’m taking your statement at face value and answering your actual question.

    Wp_mail is a pluggable function (details here).

    That means you can override the default mail handling function with your own version in a plugin or theme’s functions.php file. Just be aware, when you do this, it’s a global override for your entire site.

    The example at the bottom of the link I’ve provided is about modifying the wp_mail handler, by the way– and they briefly allude to the approach I’m guessing you probably should take.

    Perhaps replicate the existing wp_mail function in your pluggable code, but add an extra parameter such as “logged” that defaults to a value of False . . . and have an extra section of code nested inside your version of the wp_mail that executes your logging code if that value matches true.

    Then whenever you specifically want your site to log an email, in the function call be sure to include logged=true as a parameter. Make sense?

    Thread Starter GingerGeek

    (@gingergeek)

    What I mean by not a wordpress page is that it isn’t a ‘page’ where you go into Dashboard -> New Page, etc. It is a standalone, but piggybacks into wordpress

    Moderator bcworkz

    (@bcworkz)

    Grrr! “Page” What a confusing term in WP! I think I get what you’re saying though.

    It sounds like you want WP to be a mail client for your users. This is not a replacement for wp_mail() function. wp_mail() is just an extension of the PHP mail() function, it simply sends an e-mail message. It has no capability to receive mail. A mail client that interacts with your users and your registrar’s mail server to get and send mail through your domain is possible with imap and pop3 extensions of PHP, but it is probably beyond the scope of this forum IMO. While we deal with modifying the way WP works, an interactive mail client is a full blown development project that only peripherally has to do with WP.

    Or maybe it’s not as a big deal as I imagine, a lot of the various components make up WP already, just tie them together in a new way. Let’s see if anyone else has a contribution ??

    Thread Starter GingerGeek

    (@gingergeek)

    No I don’t want it to be an E-Mail client. I don’t want it to SEND the emails, instead the emails which should be SENT are just stored in the database, then when the user looks at the page it is just shows what e-mails have been sent to the user.

    To re-iterate NO E-MAILS will actually leave the wordpress installation, whatsoever, whether it is a password confirm, or anything…

    I know you are thinking about the pw reset thing, but it is not needed due to the integration with Facebook, upon an e-mail being sent to the uer they would get a notification and then on clicking it they would be taking it to a Facebook app canvas, which would point to the mail page, detailed above

    Okay, in that case the pluggable function would be the way to go then.

    Thread Starter GingerGeek

    (@gingergeek)

    Yeah, so back to the original question- how? or has it been done before???

    Thread Starter GingerGeek

    (@gingergeek)

    I don’t know how to actually code the idea at the start of this thread, I’m hoping it has either been done or it is relatively easy for me or someone to do

    Moderator bcworkz

    (@bcworkz)

    Sorry about my confusion, you kept talking about sending mail, which got my mind on the wrong track. I know you are getting frustrated, I’ve been there myself, so I understand where you’re at. A bit more patience and we’ll get you pointed in the right direction.

    Nearly, if not all mail messages sent by the WP system get composed and sent from functions in wp-includes/pluggable.php . As pluggable functions, you can simply redefine a function with the same name and your redefined function will be used instead.

    So you would copy the functions that send the mail you wish to capture and replace the wp_mail() call with your own code that stores the message data in a table. These redefined functions can be stored as part of a plugin or on a child theme functions.php.

    I sincerely hope I understand you correctly this time!

    Thread Starter GingerGeek

    (@gingergeek)

    Yes you undertand me, but my problem is:
    I have no real idea how to code it XD

    I have a logical path at the top of the thread, but my question is:
    Has this been done before, if so can I get a plugin to do it for free?
    and
    if not, how on Earth am I going to do it? (Code wise)
    Thanks for any help ??

    Thread Starter GingerGeek

    (@gingergeek)

    The human code is at the top of the thread for anyone interested in helping ??

    It’s not a small job– so, let’s break it down in pieces.

    1) How to create a new version of wp_mail.

    The link for documentation about pluggable functions is very helpful in this regard, particularly the example at the bottom.

    Naturally, the code that goes inside your version of wp_mail will be different, but let’s start there.

    Thread Starter GingerGeek

    (@gingergeek)

    read, should I actually create a plugin to do this or just hack directly into the WP pluggable??

    I was originally going to suggest doing this in the functions.php (carefully, and in stages) of your theme, but if you’d prefer to do it in a plugin– there’s no reason I can think of why it shouldn’t work.

    Here’s the next step (inside the new wp_mail you’re making)

    From $to find Real Name in UserTable

    That’s the WP User Query should be able to help you accomplish.

    Just for my own understanding, when you say “real name,” are you meaning the login or the “nice name”?

    Thread Starter GingerGeek

    (@gingergeek)

    nice name, I’ll add the code later on tonight, thanks for continued support ??

    You’re welcome. (Sorry for the delay, but I couldn’t seem to log in to www.remarpro.com this morning.)

    I believe we left off with this as our next step:

    “From $from remove everything from and including @”

    I’m interpreting that to mean, if $from is equal to “[email protected]” then rip off the right hand portion of that string, so you are left with only “joe.” (If that’s not correct, let me know.)

    Take a look at strpos() and substr functions.

    The first one will tell you which position the @ symbol holds (in our example above, it should be 3– because PHP starts counting at 0).

    The second one will let you return a portion of a string. Use the output from the first to feed the input of the second, and save the results. Make sense?

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘E-Mails Hacks’ is closed to new replies.