Hot answers tagged

30

First of all, if we take a look at implementation of wp_mail function, we will see that this function uses PHPMailer class to send emails. Also we could notice that there is hard coded function call $phpmailer->IsMail();, which sets to use PHP's mail() function. It means that we can't use SMTP settings with it. We need to call isSMTP function of PHPMailer ...


20

There's actually a filter that you can use, see abstract-wc-email.php, line 214: return apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object ); you can put the following in your functions.php: add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2); ...


19

For 2018 and onwards users: Since WordPress 4.9.0 there are new filters you can use for this (no need for a plugin anymore): wp_new_user_notification_email - customise email sent to User wp_new_user_notification_email_admin - customise email sent to Admin Usage example on email sent to Admin (you can paste this in your theme's functions.php ): add_filter(...


18

There's a few plugins that handle email notifications, but they all seem to act like a subscription service for (all) WordPress users. To notify just you when a post or page is published: /** * Send an email notification to the administrator when a post is published. * * @param string $new_status * @param string $old_status * @param object $...


17

If and when you are using wp_mail(), then you can just set Reply-To for the $headers parameter. Exemplary usage below: $to = "abc@def.gh"; $subject = "Using Reply-To with wp_mail"; $message = "This is an example for using Reply-To with wp_mail."; $headers[] = 'Reply-To: Name Name <ijk@lmn.op>'; $attachments = array(); wp_mail( $to, $...


16

To disable user email notification, add this in a plugin or theme: add_filter( 'send_password_change_email', '__return_false' ); FYI wp_password_change_notification() controls admin email notification when a user changes their password


15

Update: I have created a plugin for login, registration and retrieve password with email. https://wordpress.org/plugins/smart-wp-login/ Answer in short, you can configure WordPress to login with email. Three Steps: Remove default authentication function Add custom authentication function Change text "Username" in wp-login.php to "Email" One Note: Don't ...


15

For 2018 and onwards users: David Gard's answer still works but is old and there's a new better/cleaner way to do this (no need for a plugin anymore). Since WordPress 4.9.0 there are new filters you can use to customise registration emails: wp_new_user_notification_email - customise email sent to User wp_new_user_notification_email_admin - customise email ...


15

I finally tried using var_dump() on $item and $_product, which are both used in the email-order-items.php template. $_product revealed a post object, which itself has a post_excerpt property, which looks like it holds the contents of the "Product Short Description" from the WooCommerce product form. So, to add the description beneath the item name, I added ...


14

The following version of wp_mail() is with the patch applied of @rmccue/@MattyRob in the ticket https://core.trac.wordpress.org/ticket/15448, refreshed for 4.2.2, which allows $message to be an array containing content-type keyed alternates: /** * Send mail, similar to PHP's mail * * A true return value does not automatically mean that the user received ...


13

If you plan to use this code on frontend, I would check if email is free to use. Otherwise, you are creating a security hole. if (isset( $_POST['email'])) { // check if user is really updating the value if ($user_email != $_POST['email']) { // check if email is free to use if (email_exists( $_POST['email'] )){ // ...


13

Hook into transition_post_status, fetch the users and send an email to all users. Sample code, not tested: add_action( 'transition_post_status', 'send_mails_on_publish', 10, 3 ); function send_mails_on_publish( $new_status, $old_status, $post ) { if ( 'publish' !== $new_status or 'publish' === $old_status or 'my_custom_type' !== get_post_type( ...


13

Using the PHPMailer class with an action callback: I did some digging into the PHPMailer class and found that it supports a custom action. Here's how the callback is activated with the doCallback() method in the class. There's also a PHPMailer test on GitHub using this feature via the callbackAction() callback. We can set it up in WordPress with: $...


12

You need to use wp_update_user() for the email, as it is not user-meta but core user data. The code should look something like this: $args = array( 'ID' => $current_user->id, 'user_email' => esc_attr( $_POST['user_email'] ) ); wp_update_user( $args ); Note: that's untested, but it should work out of the box.


12

Here's one way to add this feature using the following flowline : The admin updates the user option page: -> edit_user_profile_update or personal_options_update hooks activated -> edit_user() function is called -> wp_update_user() function is called within edit_user() -> wp_insert_user() function is called within wp_update_user() ...


11

Hook into edit_post to catch changes. And take a look at wp_transition_post_status() which is called on inserts and updates: function wp_transition_post_status($new_status, $old_status, $post) { do_action('transition_post_status', $new_status, $old_status, $post); do_action("{$old_status}_to_{$new_status}", $post); do_action("{$new_status}_{$...


10

First add your email processing function and hook it to wp_ajax hooks like this using your functions.php: // if you want only logged in users to access this function use this hook add_action('wp_ajax_mail_before_submit', 'mycustomtheme_send_mail_before_submit'); // if you want none logged in users to access this function use this hook add_action('...


10

The default content type is 'text/plain' which does not allow using HTML. You can set the content type of the email by including a header like "Content-type: text/html" $headers = 'Content-type: text/html;charset=utf-8' . "\r\n"; $headers .= 'From: XXXXXX.com <info@xxxxx.com>' . "\r\n"; $subject = 'Registration from xxxxx.com' . "\r\n"; $...


9

Function wp_new_user_notification is pluggable. It means that you can override it by declaring your version of this function in your plugin/theme. So, if you wish to disable all notifications completely, do it like this: if ( !function_exists( 'wp_new_user_notification' ) ) : function wp_new_user_notification( $user_id, $plaintext_pass = '' ) { return; ...


9

Step by step: First find the file where the error message appear. I use Notepad++ and the CTRL + F command to search in files. It is a good idea to search only the first few words of the error message, because some error messages are combined of different messages. Your error message appear in wp-login.php and holy luck, only there. So let's have a look why ...


9

You want the filters... retrieve_password_message for the actual email content. Your hooked function will get the message as the first argument and the user's reset key as the second. <?php add_filter('retrieve_password_message', 'wpse103299_reset_msg', 10, 2); function wpse103299_reset_msg($message, $reset_key) { // ... } retrieve_password_title ...


9

To accomplish user activation process you need to do following steps: after create new user add a custom user field which indicates that this user has to activate his account send an email with activation code, provide a link in this email to a page where user will be activated implement activation page when user attempts to log in check if that custom user ...


8

Like SickHippie posted this functionality is native to WordPress but only for a multisite setup so here is the two functions you need to get this to work on a single site setup which are mostly code one for one from the core /wp-admin/user-edit.php file function custom_send_confirmation_on_profile_email() { global $errors, $wpdb; $current_user = ...


8

And there is another filter that will give you access to the $header variable which can allow you to BCC your emails so that you get a carbon copy of every email that goes to your clients on Woocommerce. This is just as easy as the code above except your clients will not see your email address. Just like the solution above you would add the following code: ...


8

WordPress uses custom wp_mail function, so you won't find it, if you'll search for mail. Just take a look at line 248 of wp-login.php file: http://core.trac.wordpress.org/browser/branches/3.5/wp-login.php#L248 You should find retrieve_password_message filter call there. This is the filter that returns the content of reset password message. You should also ...


8

You can intercept this email before it is sent using the phpmailer_init hook. By default, this hook fires before any email is sent. In the function below, $phpmailer will be an instance of PHPMailer, and you can use its methods to remove the default recipient and manipulate the email before it is sent. add_action('phpmailer_init', '...


7

This is a really cool idea. I don't think part 2 should be handled inside WordPress: there are plenty of RSS to email providers. They're going to be way better at that than a plugin (or theme) is likely to be. BUT we can create RSS feeds. Step one: set up a class to wrap everything up. There are a few class constants and variables here -- we'll use them ...


7

Addition to @EugeneManuilov answer. SMTP settings By default those can only get - as @EugeneManuilov already answered - be set by during a callback attached to an do_action_ref_array(). Source/core. <?php defined( 'ABSPATH' ) OR exit; /** * Plugin Name: (WCM) PHPMailer SMTP Settings * Description: Enables SMTP servers, SSL/TSL authentication and SMTP ...


7

Finally, I wrote some code and it worked very well. I hope it helps. Put this in your functions.php file //remove sitename from email subject add_filter('wp_mail', 'email_subject_remove_sitename'); function email_subject_remove_sitename($email) { $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $email['subject'] = str_replace("["...


7

The new user notification email is created and sent by the function wp_new_user_notification(), found in wp-includes/plugable.php There is no filter hook within this funciton that will allow you to manipulate the output of the email, however you can of course overwrite any pluggable function via a plugin. Note - You can only overwrite pluggable functions ...


Only top voted, non community-wiki answers of a minimum length are eligible