Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_send_email problems – not finding template email


  • Matt2012
    Participant

    @matt2012

    So I am calling this:

    $bpEmail = 'offline-payment-confirmed';
    bp_send_email( $bpEmail, $userID, $args );

    I have set up an email template which has the slug offline-payment-confirmed.

    But I am getting the error:
    missing_email

    Other than publish the template and check the slug matches what I am calling – what else could I be getting wrong?

Viewing 19 replies - 1 through 19 (of 19 total)

  • Henry Wright
    Moderator

    @henrywright

    How are you getting $userID and $args?


    Matt2012
    Participant

    @matt2012

    $args = array(
    ‘tokens’ => array(
    ‘site.name’ => ‘test’,
    ‘icom.name’ => ‘test’
    )
    );
    $x = bp_send_email( ‘offline-payment-confirmed’, 363, $args );`

    So I can stick in the userID of a known user. I have removed all tokens from the email template.

    I have fixed the error I was getting of email_missing by adding information into the taxonomy tables manually. There is no documentation about this which is odd.

    term_taxonomy
    http://www.awesomescreenshot.com/image/1747405/6c0fb29b9360b2e27a6ddc4d6065fe0e
    terms
    http://www.awesomescreenshot.com/image/1747408/d30290f3d7251a31d4b7914c93868fe6
    term_relationships
    http://www.awesomescreenshot.com/image/1747413/b3aee400bcbb45fc1968bb0d2f395af1

    So now I think email is found – but nothing is being sent and no error is being reported.


    Henry Wright
    Moderator

    @henrywright

    Are you sure nothing is being sent? Could emails be going into junk etc?


    Matt2012
    Participant

    @matt2012

    No I am using mailgun and nothing is being sent.


    Paul Wong-Gibbs
    Keymaster

    @djpaul

    > I have fixed the error I was getting of email_missing by adding information into the taxonomy tables manually. There is no documentation about this which is odd.

    I don’t think it’s explicitly documented outside of the PHP – but it is hard to find, at the best of time – but this guide https://codex.buddypress.org/emails/custom-emails/ does mention it uses a custom taxonomy, so I wouldn’t call it “undocumented”. “Very badly documented”, maybe 😀


    Paul Wong-Gibbs
    Keymaster

    @djpaul

    I remember looking at Mailgun before when someone asked about it. Looking at its code very quickly, it has an option to send via its API or not. You’ll need to disable its “useAPI” option (otherwise, it redeclares the wp_mail function, which will force BuddyPress to send plain-text only emails). Another consequence of doing this is that Mailgun configures PHPMailer to send via SMTP, and some web hosts/servers block external SMTP requests.

    If that has no affect, I think you’re going to have to do debugging inside the bp_send_email function. Specifically, I’d start looking at the return value of this line: $status = $delivery->bp_email( $email );

    With luck, PHPMailer will give you an error message with some clues in.


    Matt2012
    Participant

    @matt2012

    Ok so I have managed to fix the issue following your advice by adding a line.

    $must_use_wpmail = apply_filters( ‘bp_email_use_wp_mail’, $wp_html_emails || ! $is_default_wpmail );
    $must_use_wpmail =false; //New Line

    So why is this filter returning true?


    @djpaul


    Paul Wong-Gibbs
    Keymaster

    @djpaul

    Because… something is redefining the wp_mail function. It is most probably Mailgun, you need to change its settings as I mentioned before.


    Matt2012
    Participant

    @matt2012

    So I still have this issue. Now using the Postman plugin. Is there a simple config option to work with Postman (no body content) or do you recommend another SMTP plugin. Obviously buddypress should be able to play nicely with popular SMTP plugins?


    Buddy Quaid
    Participant

    @buddyq

    Hey there,

    Starting a similar thing and found this thread somewhat useful… can someone help me fill the gaps?

    1) @Matt2012, I use Postman too. Did you ever figure this part out?
    2) How in the world do you add a new “situation” in BuddyPress Emails? There is NO documentation on this that I can find.

    My situation:

    Using a cron job to find all sites expired or almost expired and send the users the right email. I have the arrays of users ready to go. I just need to programatically send these user ID’s to be emailed with the correct template.

    Those templates would then use their own tokens to fill in the gaps. You site: {{site.name}} is now expired. Do this and that. It expired on: {{expiration.date}}.

    How do I do this?


    Buddy Quaid
    Participant

    @buddyq

    I have an update for adding situations… since nobody from BuddyPress helps or seems to get on this site anymore, I guess I’ll post this for anyone who needs this.

    (Maybe that’s why BuddyBoss came out?)

    Anyway, I got the situations to show up by going changing to:

    plugins/buddypress/bp-core/bp-core-taxonomy.php and changing line #39 ‘show_in_menu’ to true instead of false.

    This makes it show up and you can change everything and add new ones.


    Buddy Quaid
    Participant

    @buddyq

    I’m now in the same boat with Matt2012. I am getting missing_email error.

    Not sure why. I created the email in the BuddyPress Emails and copy and pasted the used slug for the email.


    Renato Alves
    Moderator

    @espellcaste

    Hi Folks!

    I agree it is not that easy to add a new situation or a custom email. That requires custom code and a bit of knowledge of BuddyPress internals. Also that’s not documented anywhere. This is just not an area that a lot of devs look for.

    Anyway, fair to say you can hook into bp_core_install_emails and install your own emails and situations. I recommend you look at the code to know what to do to add your own email and also your custom situation: https://github.com/buddypress/BuddyPress/blob/990a4c7cf65d4e05a9a26a0a97fc9ebe276f5e4e/src/bp-core/admin/bp-core-admin-schema.php#L503

    About the email not being sent. It is important the new template has the proper name. single-bp-email-{custom-name}, if you are creating a custom e-mail, that’s how your new email template should be named for.


    Buddy Quaid
    Participant

    @buddyq

    @espellcaste thanks for the reply but i’ve read all of the resources already that you posted. My question is why use bp_core_install_emails if I can just create my email in BuddyPress Emails as shown in the screenshot below?

    My BP Email Test with a custom token for site.id
    http://scrgrb.in/76g

    BP Email slug – “your-agentassets-property-site-has-been-deactivated”
    http://scrgrb.in/76i

    My script gets all sites needing to be deactivated and sends to this function. Inside the function, I have this code:

    $args  = array(
        		'tokens' => array(
        			'site.id'             => $site_id,
        		),
        	);
        	$sent = bp_send_email( 'your-agentassets-property-site-has-been-deactivated', 'bquaid@gmail.com', $args );
            print_r($sent);

    What am I missing here? The array getting printed out is:

    WP_Error Object
    (
        [errors] => Array
            (
                [missing_email] => Array
                    (
                        [0] => bp_get_email
                    )
    
            )
    
        [error_data] => Array
            (
                [missing_email] => Array
                    (
                        [0] => your-agentassets-property-site-has-been-deactivated
                        [1] => Array
                            (
                                [no_found_rows] => 1
                                [numberposts] => 1
                                [post_status] => publish
                                [post_type] => bp-email
                                [suppress_filters] => 
                                [tax_query] => Array
                                    (
                                        [0] => Array
                                            (
                                                [field] => slug
                                                [taxonomy] => bp-email-type
                                                [terms] => your-agentassets-property-site-has-been-deactivated
                                            )
    
                                    )
    
                            )
    
                    )
    
            )
    
    )

    Buddy Quaid
    Participant

    @buddyq

    UPDATE: GETTING CLOSER… I think

    So it’s confusing…. I changed the terms to aa_site_expired instead of “your-agentassets-pro…” etc.
    I changed it to the “situation” slug instead of the “email” slug.

    Question: How do I tell it that I want to send that particular email that I created. Multiple emails can have the same “situation” selected. So how do you tell it WHICH email you want to send? Seems confusing. However, changing it now let me past the “missing_email” error and now gives me a fatal error:

    Fatal error: Uncaught Error: Call to a member function get_address() on null in /home/aabiz/public_html/wp-content/plugins/buddypress/bp-core/bp-core-functions.php:3218 
    
    Stack trace: 
    #0 /home/aabiz/public_html/wp-content/plugins/agentassets-site-manager/includes/aa-agentassets-class.php(421): bp_send_email('aa_site_expired', NULL, Array) 
    #1 /home/aabiz/public_html/wp-content/plugins/agentassets-site-manager/includes/aa-check-for-expired-sites.php(77): AgentAssets::deactivate_expired_blogs(Array) 
    #2 /home/aabiz/public_html/wp-content/themes/agent-assets/buddypress/blogs/blogs-loop.php(22): getAllBlogsDetails() 
    #3 /home/aabiz/public_html/wp-includes/template.php(724): require('/home/aabiz/pub...') 
    #4 /home/aabiz/public_html/wp-content/plugins/buddypress/bp-core/bp-core-template-loader.php(155): load_template('/home/aabiz/pub...', false) 
    #5 /home/aabiz/public_html/wp-content/plugins/buddypress/bp-core/bp-core-template-loader.php(61): bp_locate_template(Array, true, false) 
    #6 /home/aabiz/public_html/wp-content/themes/agent-ass in /home/aabiz/public_html/wp-content/plugins/buddypress/bp-core/bp-core-functions.php on line 3218

    Looks like it’s the NULL in:
    bp_send_email('aa_site_expired', NULL, Array)

    But I put in my email address in the call… why doesn’t this work?
    $sent = bp_send_email( 'aa_site_expired', 'bquaid@gmail.com', $args );


    Buddy Quaid
    Participant

    @buddyq

    I cleared up the errors and got an email to send.

    Question:

    Is it possible to create a new template for certain emails? If I create a new template called single-bp-email-custom-2.php and put that in my /MY-THEME/buddypress/assets/emails folder. How do I tell bp_send_email() function to use it?


    shanebp
    Moderator

    @shanebp

    How do I tell bp_send_email() function to use it?

    This may be helpful: BP Email Assign Templates


    Buddy Quaid
    Participant

    @buddyq

    Thanks!


    Renato Alves
    Moderator

    @espellcaste

    The main reason to use the hook is in case another plugin or yourself try to reinstall the emails. If one does that, that email you showed creating will be deleted and you will have to recreate it by hand again. That doesn’t seem to be desireable.

    Also, creating via the hook, you can use the correct name when sending the email. You say you read it but your last question implies you don’t know how you are doing and seems to be trying a try and catch attempt. Meaning, trying something and seeing if it works.

    I’d recommend doing in the BuddyPress way, the correct way, to avoid problems in the future when upgrading BuddyPress or reinstalling emails.

Viewing 19 replies - 1 through 19 (of 19 total)
  • You must be logged in to reply to this topic.
Skip to toolbar