Hot answers tagged

34

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(...


30

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


25

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


25

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, $...


24

To disable Admin email notification when a user resets their own password, create a Plugin (or Must Use Plugin) using the following code snippet: /** * Disable Admin Notification of User Password Change * * @see pluggable.php */ if ( ! function_exists( 'wp_password_change_notification' ) ) { function wp_password_change_notification( $user ) { ...


23

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 ...


21

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 ...


18

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 ...


17

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 ...


15

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( ...


14

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: $...


13

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

Here is the sample code for using output buffering. You will be able to access all the variables inside the template which are defined above "include line". WordPress: Include template in the email. ob_start(); include(get_stylesheet_directory() . '/assets/email-templates/booking-details-template.php'); $email_content = ob_get_contents(); ob_end_clean(); ...


11

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"; $...


10

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 ...


10

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 ...


10

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', '...


10

The problem is the < and > which surround the reset URL in wp-login.php. You can remove them using retrieve_password_message in your theme functions.php file like below: add_filter("retrieve_password_message", "mapp_custom_password_reset", 99, 4); function mapp_custom_password_reset($message, $key, $user_login, $user_data ) { $message = "...


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

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: ...


9

Just wanted to let you know you have get_user_meta and get_userdata. The email address can be found using the get_userdata function. For the current user this code can apply: <?php $user_id = get_current_user_id(); $user_info = get_userdata($user_id); $mailadresje = $user_info->user_email; echo $mailadresje; ?> Please note this is ...


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

Option 1: Remove the 'to' argument from wp_mail function in WordPress, it will keep your system running without sending any default WordPress emails. add_filter('wp_mail','disabling_emails', 10,1); function disabling_emails( $args ){ unset ( $args['to'] ); return $args; } The wp_mail is a wrapper for the phpmailer class and it will not send any ...


8

The other answers to this post, while providing a working solution, don't address the security issue of storing your SMTP credentials in a plugin file or functions.php. In some cases that may be OK, but best practices would dictate storing this information in a more secure fashion. There's really not a good reason to not follow best practices when it comes ...


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

TLDR, the simple solution is: add_action('phpmailer_init','wp_mail_set_text_body'); function wp_mail_set_text_body($phpmailer) { if (empty($phpmailer->AltBody)) {$phpmailer->AltBody = strip_tags($phpmailer->Body);} } Then you don't need to set the headers explicitly at all, the header boundaries are set correctly for you. Read on to for a ...


8

You can use user_register hook add_action( 'user_register', 'my_registration', 10, 2 ); function my_registration( $user_id ) { // get user data $user_info = get_userdata($user_id); // create md5 code to verify later $code = md5(time()); // make it into a code to send it to user via email $string = array('id'=>$user_id, 'code'=>$...


7

get_user_meta retrieves a single meta field or all fields of the user_meta data for the given user. This means that all the values that are stored in user_meta table can be got using get_user_meta. Email is not stored as meta data so you cant get email using get_user_meta. Email is stored with username and password in user table as user data.


7

Per my comment to your question, I believe the problem is that includeing files, whether directly or using get_template_part isn't likely to give you a string to pass to $body and that is going to cause errors in the code, or at the very least unespected behavior. I would avoid reading files into memory and just create a function that returns your $body ...


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