Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to translate email sending by plugin WP Mail SMTP

On this example we use a filter to translate our email message based on this doc : https://wpmailsmtp.com/docs/setting-a-custom-reply-to-email/

Weglot can translate wp_mail emails natively — just enable the Translate emails option in the Weglot settings. Use the snippet below only if you need custom handling on top of the built-in option (for example with WP Mail SMTP).

This example translates the email message body into the current language:

function wp_mail_smtp_weglot( $args ) {
	$original_lang    = weglot_get_original_language();
	$current_language = weglot_get_current_language();
	if ( $original_lang == $current_language ) {
		return $args;
	}

	if ( ! empty( $args['message'] ) ) {
		$translate_service = weglot_get_service( 'Pdf_Translate_Service_Weglot' );
		$translate_message = $translate_service->translate_pdf( $args['message'], $current_language );
		$args['message']   = $translate_message['content'];
	}
	return $args;
}

add_filter( 'wp_mail', 'wp_mail_smtp_weglot', PHP_INT_MAX );

Last updated