Hot answers tagged

36

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


31

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


26

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


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

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


19

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


18

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


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

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


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

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


10

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


10

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'=>$...


9

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


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

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

There's a great article explaining how to hook into 2 filters for this at https://web.archive.org/web/20200216075253/http://www.sourcexpress.com/customize-wordpress-comment-notification-emails/ To send your notifications to a particular user and not the site admin, try this for a user with ID 123: function se_comment_moderation_recipients( $emails, $...


8

To answer your specific question, "How can I modify the default reset (lost) password email text," the answer would be to use the retrieve_password_message filter. And ultimately that might be a way to solve your problem. But I think you need to dig a little deeper to figure out what's really going on. In your question you asked about modifying the "...


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

Try this instead. There was some internal restructuring in CF7 3.9. add_action('wpcf7_before_send_mail','send_pdf'); function send_pdf( $cf7 ) { $id = $cf7->id(); if ($id==741){ $submission = WPCF7_Submission::get_instance(); $submission->add_uploaded_file('pdf', get_template_directory().'/test.pdf'); } } This should ...


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


7

The problem I think the problem here is that you're generating an infinite loop, by placing wp_mail() inside the $phpmailer->action_function callback, that fires after each email. Each time you send an email with wp_mail(), you call wp_mail() again, and again, and again ... etc Possible workaround You should instead use, for example, the following ...


7

This is a feature since 4.3.0, as part of WordPress's improved security measures (check out the source on the WordPress code reference). You can disable it with the following filter: add_filter( 'send_email_change_email', '__return_false' );


7

If I understand you correctly, then you only want to change the text of the mail. This you can do via the filter hook password_change_email. No need to redeclare the function, which you actually can't do. Below you find an example on how to use the password_change_email filter to change your message text. add_filter( 'password_change_email', '...


7

Thanks to the above, I've realized my central mistake -- I didn't quite realize that the arguments being passed in were a multi-dimensional array. For now, I've re-implemented the function thus: function ws_add_site_header($email) { $email['headers'][] = 'X-WU-Site: ' . parse_url(get_site_url(), PHP_URL_HOST) ; return $email; } My ...


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