Skip Navigation
availability:

WPML Version: 3.2.0

description:

This action hook switches the language of your emails to the user’s preferred language. This is helpful when you need to send emails in different languages. Make sure to reset the language back by using wpml_restore_language_from_email. Also, see the extended documentation: Sending Emails with WPML.

If the given email is not registered, nothing will happen.

type:
action
category:
Retrieving Language Information for Content
parameters:

$email
(string)
The user email.

hook example usage:

Example

Send an email to all users in their language.

$all_users = get_users();

foreach( $all_users as $user ) {
	// Switch language to user language.
	do_action('wpml_switch_language_for_email', $user->user_email );

	$subject = __('Hello, World!', 'text-domain');
	$message = __('This is our newsletter', 'text-domain');

	wp_mail( $user->user_email, $subject, $message);

	// Switch language back.
	do_action('wpml_restore_language_from_email');
}