PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

wp_mail not sending inside gform function

  1. Is there any reason why wp_mail would not work inside this function?

    [php]
    add_action("gform_after_submission_25", "replymessage", 10, 2);
    function replymessage($entry,$form) {
    	global $current_user;
    	$message = array(
    	'post_title' => 'ref#'.$current_user->ID,
    	'post_type' => 'message',
    	'post_status' => 'publish',
    	'post_author' => $current_user->ID
    	);
    	$post_id = wp_insert_post($message);
    	add_post_meta($post_id,'ecpt_messagecontent',$entry['1']);
    	add_post_meta($post_id,'ecpt_messagestatus','unread');
    	add_post_meta($post_id,'ecpt_messagerecipient',$entry['2']);
    	add_post_meta($post_id,'ecpt_messagereply',$entry['3']);
    
    	//update post as read
    	update_post_meta($entry['3'],'ecpt_messagestatus','replied');
    	wp_mail(get_user_meta($entry['2'], 'user_email', true),'You have a new message from '.get_user_meta($current_user->ID, 'first_name', true),$entry['1']);
    }

    I've tested wp_mail outside this function and it works fine???

    Could it be something to do with the order this action is being fired in?
    everything else inside this function works fine except for the mail side of things
    I had to do this this way so that the recipient never finds out the email address of the person sending the message

    Thanks in advance

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink
  2. just so you know, even if I add in wp_mail('my@email.com','test','test') at the end of the function it still won't work

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink
  3. I'm not entirely sure. I'm not aware of any issues with using wp_mail() this way but I'll pass this along to one of our developers who will respond back.

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink
  4. Hi Tom,

    I tested this with the following code without issue:

    http://pastie.org/3054943

    Could you do the same and let me know?

    Posted 12 years ago on Thursday December 22, 2011 | Permalink
  5. Thanks guys,
    @david, your code works on my site perfectly, this is very strange. Everything in the function i posted works EXCEPT for the email side of things, yet your function works fine. I can't figure this at all!

    Posted 12 years ago on Thursday December 22, 2011 | Permalink
  6. Hi Tom Tong,

    Try moving your wp_mail() call to the top of the function. Also, are you working with WP_DEBUG set to true? That might give your a warning as to what is going on.

    Posted 12 years ago on Thursday December 22, 2011 | Permalink
  7. I have fixed it guys, thanks for your awesome support as usual and Merry Christmas!

    Posted 12 years ago on Thursday December 22, 2011 | Permalink
  8. Awesome! Merry Christmas. :)

    Posted 12 years ago on Thursday December 22, 2011 | Permalink

This topic has been resolved and has been closed to new replies.