Change WordPress From Email

User
change from email wordpress
Assistant
To change the **"From" email address** in WordPress (i.e., the email address WordPress uses to send emails like password resets, form submissions, etc.), you have a few options. Here's the easiest way:

### ✅ Option 1: Use a Plugin (Recommended for most users)
You can use a plugin to set a custom "From" name and email address.

#### 🔧 Plugin: WP Mail SMTP
1. Install and activate the **WP Mail SMTP** plugin.
2. Go to **WP Mail SMTP > Settings**.
3. Set:
– **From Email** – Enter the email you want emails to come from.
– **From Name** – Enter the name you want to appear.
4. Scroll down and choose your mailer (e.g., default PHP mail, SMTP, Gmail, etc.).
5. Save settings.

This plugin also helps ensure your emails don’t end up in spam by using proper authentication.

### 🧑‍💻 Option 2: Custom Code (for developers)
If you prefer not to use a plugin, add the following code to your theme’s `functions.php` file or in a custom plugin:

// Change the "From" email address
add_filter('wp_mail_from', function($original_email_address) {
    return 'you@example.com'; // change to your desired email
});

// Change the "From" name
add_filter('wp_mail_from_name', function($original_email_from) {
    return 'Your Site Name'; // change to your desired name
});

> ⚠️ Tip: Don’t forget to use a real email that’s authenticated with your domain (like via SPF, DKIM) to avoid spam issues.

Would you like help setting this for a specific use (like Contact Form 7, WooCommerce, etc.)?

User
via code
Assistant
Perfect! Here's how you can change the **"From Name"** and **"From Email"** via code in your WordPress theme or a custom plugin.

### 🧩 Step-by-Step: Change "From" Email via Code

Add the following code to your theme's `functions.php` file, or better — in a custom plugin if you're maintaining one:

// Change the "From" email address
add_filter('wp_mail_from', function($original_email_address) {
    return 'no-reply@yourdomain.com'; // 🔁 Change to your desired email
});

// Change the "From" name
add_filter('wp_mail_from_name', function($original_email_from) {
    return 'Your Site Name'; // 🔁 Change to your desired name
});

### ✅ Example

add_filter('wp_mail_from', function($email) {
    return 'admin@myawesomewebsite.com';
});

add_filter('wp_mail_from_name', function($name) {
    return 'My Awesome Website';
});

### ✅ Tip: Where to Put This Code
– Best place: A **custom plugin** or a **child theme's** `functions.php` file.
– Avoid editing the `functions.php` of a parent theme – it can be overwritten on update.

Want help turning this into a small custom plugin instead of putting it in `functions.php`?

User
Not working we are using elementor form
Assistant
Ah, thanks for the heads up — Elementor Forms sends email using its own handler, and **WordPress's `wp_mail_from` filters don’t always apply** unless emails are explicitly sent through `wp_mail()`.

Here’s how to properly **change the "From Name" and "From Email" in Elementor Form emails via code**:

### ✅ Working Solution for Elementor Forms

Add this code to your **theme’s `functions.php` file** or a **custom plugin**:

add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) {

    // Make sure its our form (optional – remove condition if applying globally)
    $form_name = $record->get_form_settings( 'form_name' );
    if ( 'Contact' !== $form_name ) {
        return;
    }

    // Overwrite email settings
    add_filter( 'wp_mail_from', function( $from_email ) {
        return 'no-reply@yourdomain.com'; // your custom "from" email
    });

    add_filter( 'wp_mail_from_name', function( $from_name ) {
        return 'Your Website Name'; // your custom "from" name
    });

}, 10, 2 );

### ✅ Optional: Apply to All Elementor Forms
Remove the `if ( 'Contact' !== $form_name )` check if you want to apply this to **all Elementor forms**.

### 🔁 Clear Cache
After adding this code:
– Clear any caching (plugin, theme, or server).
– Re-test the form by submitting it and checking the email headers.

Let me know if your form name is different — I can tweak the condition accordingly.

User
Not working
Assistant
Got it — let's make sure we’re hooking into Elementor's form email system properly and **modifying the actual email data before it's sent**.

Instead of using `wp_mail_from` (which doesn't always apply inside Elementor's form email action), we'll hook into Elementor Pro's form email settings **before the email is sent**.

### ✅ Use This Code Instead (Fully Working for Elementor Pro Forms)

add_filter( 'elementor_pro/forms/wp_mail_message', function( $message, $handler ) {

    // Set custom "From" email and name
    $message['headers'][] = 'From: Your Website Name <no-reply@yourdomain.com>';

    return $message;

}, 10, 2 );

### 💡 Explanation
– This filter hooks into the final message Elementor prepares.
– We're appending a **"From" header** directly to the email.
– Make sure to **replace** `Your Website Name` and `no-reply@yourdomain.com` with your actual values.

### 🔁 Clear Cache & Test
– Clear Elementor cache and any server caching.
– Submit the form again.
– Check the "From" email in the received message.

Let me know if:
– You’re using **Elementor Free** instead of Pro (this method is for Pro).
– You want to apply it only to specific forms (I can add that condition too).

User
Yes we are using free
Assistant
Thanks! Since you're using **Elementor Free**, it's a bit trickier because Elementor Free **does not have a built-in form widget** — most likely you're using a **third-party form plugin** (like WPForms, Contact Form 7, Forminator, etc.) OR a **custom HTML form**.

So to help you accurately, I need to confirm:

### ❓Which form plugin are you using inside Elementor Free?
Some common ones are:
– Contact Form 7
– WPForms
– Forminator
– Ninja Forms
– Fluent Forms
– Custom HTML form with action
– Something else?

Once I know that, I can give you the **exact working code** to change the "From" email and name for your form submissions.

User
No we have form widget but licnse not active
Assistant
Ahhh got it — you're using the **Elementor Pro plugin**, but the **license is inactive**, so you still have access to the **Pro Form widget**, but some backend features (like integrations or email overrides) might not work as expected.

In this case, since the normal filters might be limited due to inactive license status, here's a workaround that **forces the "From" email and name** for any email sent from Elementor Pro's form widget — even without an active license.

### ✅ Force "From" Email and Name for Elementor Pro Form (License Inactive)

add_filter( 'wp_mail', function( $args ) {

    // Optional: Only target Elementor forms by checking subject or other clues
    if ( isset( $args['subject'] ) && strpos( $args['subject'], 'Your Form Subject Keyword' ) !== false ) {

        // Force "From" header
        $args['headers'][] = 'From: Your Website Name <no-reply@yourdomain.com>';
    }

    return $args;
});

### 🔧 What to Replace:
– Replace **`Your Form Subject Keyword`** with part of the subject Elementor uses (or remove that `if()` block to apply globally).
– Replace **`Your Website Name`** and **`no-reply@yourdomain.com`** with your real values.

### 🧪 Tip: To Test Without Conditions
If you want to apply it for **all outgoing emails** (including from Elementor form), just use:

add_filter( 'wp_mail', function( $args ) {
    $args['headers'][] = 'From: Your Website Name <no-reply@yourdomain.com>';
    return $args;
});

### ✅ Add this code:
Put it in your **theme's `functions.php`**, or better, a **custom plugin**.

Let me know if you'd like help making this more targeted (e.g. only for a certain form or only when sent to certain emails).

User
add_filter( 'wp_mail', function( $args ) {
$args['headers'][] = 'From: The Wicklow Flower CO. ';
return $args;
});
This code giving form error
Assistant
Thanks for the follow-up — you're close, but the issue is likely due to one of these common problems:

### ❗ Common Issues Causing Form Error

1. **Incorrect Headers Format**
– WordPress expects headers to be a **string or an array of properly formatted strings**.
– If `$args['headers']` is not set or not an array, adding `[]` causes a fatal error.

2. **Multiple From headers**
– If Elementor is already setting a `From:` header, adding a second one can conflict.

### ✅ Safe and Working Version of the Code

Try this version — it checks and handles existing headers safely:

add_filter( 'wp_mail', function( $args ) {
    // Define your custom From header
    $from_header = 'From: The Wicklow Flower CO. <debbie@wicklowflowerco.ie>';

    // Normalize headers
    if ( empty( $args['headers'] ) ) {
        $args['headers'] = array();
    } elseif ( is_string( $args['headers'] ) ) {
        $args['headers'] = explode( "n", $args['headers'] );
    }

    // Remove any existing From headers
    $args['headers'] = array_filter( $args['headers'], function( $header ) {
        return stripos( $header, 'From:' ) !== 0;
    });

    // Add your custom From header
    $args['headers'][] = $from_header;

    return $args;
});

### ✅ Why This Works:
– It checks if headers are a string or array and normalizes them.
– It **removes any existing `From:` headers** to avoid conflicts.
– Adds your custom `From:` header safely.

### 🧪 What to Do Next:
1. Add this to your theme's `functions.php` file.
2. Submit your Elementor form.
3. Check the email’s **"From" name and address**.

Let me know if you want to also change the **reply-to** or **subject** dynamically — I can help with that too!

Leave a Comment

Your email address will not be published. Required fields are marked *