views:

157

answers:

1

I have a client that is using WP for a CMS. He wants un-registered users to be able to submit content. It's a form that has the following fields:

Your name Your email Friend's name Friend's email Message Submit

Then the message would be posted on the site (as a comment) and that message/comment would then be emailed to the Friend's email address. So the email would look like so:

Hey Friend,

Your name said something about you. Isn't that cool?

Blah blah blah blah blah and etc.

How difficult would it be to accomplish this and if it is possible, can someone please point me in the proper direction? I figure there are fields I need to add to the comment form and that I can figure out on my own. It's the whole sending the actual comment in an email to that email address that's causing issues for me.

TIA!

+1  A: 

Create a new comments template with your extra fields. See more about how to do this at the Codex.

Add a hook for the 'comment_post' action. It's defined around line 997 of comment.php. At this point, the comment will have already been inserted into the database. You can send your email here using the wp_mail function defined around line 254 of pluggable.php.

If you want to do some preprocessing on the comment text, 'pre_comment_on_post' might be your best bet. It's defined around line 34 of wp-comments-post.php.

scompt.com
Does this mean that I need to write a function and put it in the functions file? And as part of this function, I create a mail send script or do you know how I can tap into WordPress' ability to send emails. (What actions I need to look for, etc.)Thanks for the previous answer.
Justice Is Cheap
Yup, writing a function in the functions.php file is probably the easiest way to add the hooks. I've edited my answer with a link to the wp_mail function that you can use.
scompt.com