Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am currently posting from the front end using a similar model as http://voodoopress.com/2011/03/review-of-posting-from-front-end-form/. I want to send an email to certain addresses based on the value of the "problem_type" field. This is what I have so far. This does not send anything at all, but I am at a dead end. Ideas? I only need 3 different emails. 1 if value is computers, 1 if value is phones, and every other value can be sent to a 3rd email address.

function new_post_creation_email($pid) {
    $problem_type = get_post_meta($pid, 'problem_type', true);
    $description = 'post_content';

    if ($problem_type == 'phones') {
        $to = '1st email here';
    } elseif ($problem_type == 'computers') {
        $to = '2nd email here';
    } else {
        $to = '3rd email here';
    }

    $subject = "New Ticket in ' . echo get_post_meta($pid, 'problem_type', true) . ";
    $message = "A user profile has been updated\n\n";
    $message .= print_r($description,true);
    @wp_mail( $to, $subject, $message);
}

add_action('wp_insert_post','new_post_creation_email');

Obviously the "1st email here" etc have been replaced with text email addresses in the real code.

share|improve this question
    
can you use print_r() in assignment? I don't think so. –  Milo Jul 8 '11 at 16:09
add comment

1 Answer

Here are a couple of things:

  1. You're mixing ' and " in a very bad way!
  2. You're echoing inside a string. Don't do that.
  3. You're silencing any errors on the wp_mail function, so if WordPress is giving you an error you'll never see it!

First, fix your ' and " problem. Your $subject definition should read like this:

$subject = "New Ticket in " . get_post_meta($pid, 'problem_type', true);

This fix also fixes the echo problem.

Next, remove the @ from in front of wp_mail and turn on WP_DEBUG in your config files so you can see any errors that crop up.

share|improve this answer
    
Thanks EAMann! This got it to work...I sheepish grin had it in the page template that was creating the post. The final fix was to place this function in functions.php. Beautiful! –  Matt Pritchett Jul 8 '11 at 17:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.