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);


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

  • can you use print_r() in assignment? I don't think so.
    – Milo
    Jul 8, 2011 at 16:09

1 Answer 1


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.

  • 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! Jul 8, 2011 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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