Skip Navigation

[Resolved] CRED Setting the sender email and name

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I change the "From" Email in the CRED Notifications dynamically according some custom values?

Solution:
1. You can use the WordPress native filter for outgoing emails, or,
2. You can use the CRED API we crafted for it:

Both approaches involve Custom Code.

You can see examples at the below links

Relevant Documentation:
https://toolset.com/forums/topic/cred-setting-the-sender-email-and-name/#post-380836
https://toolset.com/documentation/programmer-reference/cred-api/#cred_mail_header

This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 2.49 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by dianaM-4 8 years ago.

Assisted by: Beda.

Author
Posts
#379815

I am trying to set the sender email-adress and name (the from-fields in the email-notifications) to the name of the user, which is logged in.

I followed the instructions on this URL: https://toolset.com/forums/topic/how-to-set-the-set-from-details/ The sender email-adress now works fine. I tried to manipulate the sender-name in the same way:

// Changing sender-name, when given sender-name in CRED is "Sender"
add_filter( 'wp_mail_from_name', 'custom_sendername' );
function custom_sendername( $original_email_from ) {
    if ( isset( $_POST['wpcf-sendername'] ) && $original_email_from == 'Sender' ) {
        return $_POST['wpcf-sendername'];
    } else {
        return $original_email_from;
    }
}

I defined the wpcf-sendername correctly in the CRED-form and it is stored correctly in my database. But the sender-name in the retrieved email still shows "Sender". Is this wp-filter not working? Or what am I doing wrong?

#379958

This is not Toolset API Code.

For WordPress API code issues please contact the WordPress forum here:
https://wordpress.org/support/

We do not provide a API to manipulate the Email Details, because you would need to update a Array in the Database (the "from" name is stored in _cred_notification for the Notification Post ID)

What I can do for you is request a new Filter API from the CRED DEV so in future you could apply a Toolset API Filter for this.

Thank you

#380443

Hmmm … don't know, what to say. Isn't it an usual behaviour, that an email sent by a contact-form shows the senders email-address and his name? I think, there are many contact-form-plugins out there, which are doing that out of the box. So it would be great, if there would be a possibility directly in CRED, to choose the data for the "from"-fields. In a similar way as it is for the "to"-fields. But if that's not possible – yes, a Toolset API Filter would work, too 😉

(I know, there could be a spam-issue when sending from another domain … but anyway, every client expects, that he's getting the user-email in the same way as he would, when it was sent directly from his user.)

Do I understand it right: The wp-filter wp_mail_from_name doesn't work for CRED, because CRED gets his from-data out of the database? But the from-email-address in CRED does that too, doesn't it? But there the workaround from the linked post above did the trick. So what's the difference between those fields?

#380836

It's not usual, specially not in WordPress

WordPress can even stop your emails to be sent, or other receivers can abort or classify as Spam, if the email is not by the Site (WordPress) or acknowledged as "safe" by the receiver.

What I suggest for you to solve this is to create a Custom Field where the User can enter his contacts.

As you say, your code for the sender Email works, so you can as well keep it as is.

The Sender Name is stored as Array, and I can not provide a Custom Code that updates that Array.

What I can do is escalate a Feature Request to create a API Filter for this, or even a more advanced GUI, so you can do this easily.

You can also try this:

add_filter('wp_mail_from', 'new_mail_from', 99);
add_filter('wp_mail_from_name', 'new_mail_from_name', 99);

function new_mail_from($old) 
{
    return 'your@email.com';
}

function new_mail_from_name($old) 
{
    return 'Your Name or Your Website';
}

I included above both the Name and email

Of course you can customize it as you want.

Mind the priority 99.

Thank you

#381521

Thanks Beda, I think, that I'm getting what you suggest. I'll give it a try. But unfortunately I can't get on this project before the end of next week. So I have to leave this ticket as open till then.

Yes, please, I would appreciate a Feature Request for this. Thank you!

#381707

Sure let me know if any doubts or questions arise.

Thank you for your patience.

#382193

Not really? Right now I see, that I forgot to set the priority 99 … That would have been so easy 🙂
Thanks again, Beda. Now everything works fine!
Many greeting from cloudy Vienna ...

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.