I assume your problem is the wp_email()
calls are not working? The function has specific parameters which must be in very specific formats. Review the documentation. Your usage is not matching this. Complicating things is the ‘@’ in front of the function means PHP should suppress errors from this function, even if WP_DEBUG is defined as true.
For your own sanity, remove the @ and set WP_DEBUG to true in wp-config.php so you are notified about what errors are occurring. Replace the @ and define WP_DEBUG as false once you’re sure everything is working properly.
Let’s look at the admin wp_email()
call. You have
wp_mail(get_option('admin_email'), sprintf(__('Ask Become Topic Notification - %s', self::TD), $blogname, $title), $message);
The documentation has
wp_mail( $to, $subject, $message, $headers, $attachments );
The first parameter is the recipient as string. That looks OK.
Next you have
sprintf(__('Ask Become Topic Notification - %s', self::TD), $blogname, $title)
You’ve allocated space for one string variable, but you provide two variables to fill one space. You need another %s somehow or one less variable.
The third parameter is $message in both cases, and it’s assignment appears correct.
The remaining parameters are optional and you don’t provide them. All good there. The only problem is the missing %s or extra variable.
Now the user email. You have
wp_mail($author->user_email, $blogname, $title, $message);
You already dropped the @ here. It’d be a good idea to put one here once this is all said and done.
First parameter is the recipient, this looks OK.
Next is subject. You have the blog name. Not a great subject, but technically OK.
Third is the message body. You have $title. This is probably technically acceptable, it’s a string. Surely not what you intended though.
Fourth is the headers parameter. This parameter has very specific requirements, of which what you have in $message is almost certainly wrong. Obviously, $blogname and $title need to be combined somehow, you could do something similar to what’s done in WP core:
sprintf('[%s] Content: "%s"'), $blogname, $title )
That should take care of the mail functions. There may be other issues. Having WP_DEBUG defined as true should help you locate and fix any other errors. If you get stuck again, come on back ??