---
title: How to Add Magic Login to Any of Outgoing Emails?
description: "It's easy to integrate Magic Login links with outgoing WordPress emails. Simply use the {{MAGIC_LINK}} placeholder, and it will be converted to an actual login link when the email is sent. ## Personalization at Its Best To add a personal…"
url: "https://handyplugins.co/docs/how-to-add-magic-login-to-any-of-outgoing-emails/"
updated: "2024-05-14"
category: Magic Login Pro
---

# How to Add Magic Login to Any of Outgoing Emails?

It's easy to integrate Magic Login links with outgoing WordPress emails. Simply use the {{MAGIC_LINK}} placeholder, and it will be converted to an actual login link when the email is sent.

## Personalization at Its Best

To add a personal touch to your emails, we're introducing additional placeholders for further customization. You can use `{{FIRST_NAME}}`, `{{LAST_NAME}}`, `{{FULL_NAME}}`, `{{DISPLAY_NAME}}`, and `{{USER_EMAIL}}` to make each email feel tailored to the recipient, enhancing engagement and trust.

## Limitations

For security reasons, some limitations similar to those of the auto-login links feature apply here as well:

- Multiple Recipients: Magic Login links cannot be sent to more than one recipient, including CC/BCC addresses.
- Excluded Emails: Emails excluded from sending will not contain Magic Login links.
- Non-existent Users: If the email address provided does not match an existing user, the Magic Login link will not be generated.

## Hooks

**magic_login_replace_magic_link_in_wp_mail**: to control {{MAGIC_LINK}} behaviour.

e.g: Let's use this filter to check if the user is an admin and return false if they are. This will abort the email sending process. Here's how you can do it:

```
add_filter( 'magic_login_replace_magic_link_in_wp_mail', 'custom_magic_link_control_for_admin', 10, 3 );

function custom_magic_link_control_in_wp_mail_for_admin( $replace, $atts, $user ) {
	// Check if the user is an admin
	if ( user_can( $user, 'administrator' ) ) {
		// Abort the email sending process
		return false;
	}

	return $replace;
}
```

magic_login_replace_magic_link_in_wp_mail_message: to modify generated magic link for wp_mail integration.

e.g: Add redirect_to parameter based on the role.

```
add_filter( 'magic_login_replace_magic_link_in_wp_mail_message', 'add_custom_redirect_based_on_role', 10, 2 );

function add_custom_redirect_based_on_role( $magic_link, $atts ) {
	// Get the user by email
	$user = get_user_by( 'email', $atts['to'] );

	// Check if the user is an administrator
	if ( user_can( $user, 'administrator' ) ) {
		// Replace the magic link with a custom URL
		$magic_link = add_query_arg( 'redirect_to', urlencode( admin_url() ), $magic_link );
	} else {
		$magic_link = add_query_arg( 'redirect_to', urlencode( site_url( '/my_account' ) ), $magic_link );
	}

	return esc_url( $magic_link );
}
```
