I've noticed in the Email Notification section of CRED post forms a 'Set From details' sub section and I'm wondering why it's not working for me!
I have a very simple plugin which allows me to use an SMTP email server instead of the native wordpress mail function (more reliable etc). There's nothing fancy about it, I just tell it the email address to use, the From name and the mail server address and that's it. So currently, any emails sent via CRED show as coming from me@mydomain.com (all my post forms have the two 'set from' fields left blank).
I had expected that if I populate the two 'Set From' fields with a different email address and a different from name (e.g. him@hisdomain.com, John Smith) that the recipient would perceive the email to have come from John Smith having email address him@hisdomain.com but this isn't the case (they still show as coming from me@mydomain.com).
Is this because I'm not using the native wordpress mail function or am I doing something wrong?
Thanks
Hi,
In order to help pinpoint the issue, could you temporarily disable the SMTP plugin and allow CRED to send the emails using the native mail function? Observe the "from" address in the emails sent by CRED. Based on the results of that test I can determine the best approach here.
Hi Christian
Using the native wordpress email function, the 'from' name is 'Wordpress' and the sender's email is 'wordpress@mydomain.com'.
Does this help?
Okay this is the default "from" address, so that appears to work as expected. While the SMTP plugin is temporarily disabled, add a custom "from" email address and name and send another test email to yourself. Do these settings get applied to the test email?
Hi Christian
This is where it gets interesting! I've tried this on two multi-site installations. On the site that uses my hosting provider's email servers, disabling the SMTP plugin and adding the 'Set From' details works (the Set From details are used). On the site that uses Google's GSuite Mail Servers, the email isn't sent at all; it's not even appearing as Junk and isn't triggering a Message Delivery Failed Notification either.
Any ideas please?
What are the subject and body of the emails? Is it possible they are being filtered?
As a test, perform some task that triggers a standard WP email on the server that uses Google Mail. For example, configure a new WP user account, triggering a standard WordPress new user email to yourself. I would like to know if any WordPress mail gets sent, or if only CRED mail is failing.
The subject and body are the same as they were with the 'Set From details' blank (text with some shortcodes and a bit of HTML). Normally, if Google perceives an outgoing email as spam, an undelivered message is sent (but it wasn't). Not sure about filtering. I am beginning to wonder whether Google is saying hey that's not the email associated with the account so we can't use it as a from/reply to address and so we're also not going to send it at all. Does that make sense?
On the site that uses Google and with SMTP plugin de-activated, I added a new User to one of the sites (blogs) and allowed the confirmation email to be sent. The return address on that email is the address associated with my Google mail account (which is also the email for the site's Super Admin in case that's relevant info). I'm not sure if that's what I expected!!
Does that provide any further clues?
So what happens if you set the CRED notification "from" address to be your site's Super Admin address on the Gmail server without SMTP plugin enabled? Do these messages go through?
Hello again
This morning I tried 3 different emails in the From field (with SMTP plugin disabled); a hotmail address (a contact in the Google account), the Super Admin Email on the site and then an 'external' email (Super Admin address on the other multi site install & not a contact on the Google account). This is what came through:-
Using the hotmail address, the email came through showing the From name as set in the hotmail account, selecting Reply shows the name I set in the Set From details and the hotmail address.
Using the address for Super Admin, no emails is sent.
Using the 'external' address, the email came through showing the From name as set in the Set From details, selecting Reply shows the same and the 'external' address.
It's a little curious but does rule out my theory as to what Google might be doing so maybe there's a little progress there?
What do you make of it?
Hi Christian
A further update!
I've been playing around with this a bit more. I've tried an alternative SMTP plugin and also tried adding code to my functions file to set email to use SMTP instead and nothing changes. The general common feature seems to be that's possible to override the From Name but not the From email.
I also came across this in the Codex at https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_mail_from :-
To avoid your email being marked as spam, it is highly recommended that your "from" domain match your website.
Some hosts may require that your "from" address be a legitimate address.
This bit of info changes how I'm going to approach things and so the issue with the Set From details not working ceases to be an issue (at least for me/in this instance).
For the benefit of others, I did try two more scenarios:-
Using SMTP, I put the From address in the settings as one that matches the domain and in the CRED form I put a different one matching the domain (both different to the Google email address and the Super Admin address). The return address was the From address in the SMTP settings not the one on the CRED form.
Without SMTP no emails are sent.
It would seem, therefore, that the Set From details in the CRED form isn't functioning as expected. Whilst no longer an issue for me in this instance, it may be an issue further down the line/on a different website and for others now so if you agree with my conclusion and feel it worthy of further investigation, I'm happy to help out with the troubleshooting if I'm able. Let me know?
The return address was the From address in the SMTP settings not the one on the CRED form.
Right, since SMTP takes over sending the email, SMTP is overriding CRED's "from" settings. The SMTP servers / plugins I have used allow you to specify a "from" email address in their settings. If no "from" email address is specified, the admin email address is the default. That means that no matter what the "from" address is when the email is triggered, SMTP will override it.
Let me reach out to the team and get some feedback on SMTP integration - it's not something I'm very experienced in. Which SMTP plugins have you been trying? What code did you add to functions.php to enable SMTP without the plugins?
Hi Christian
The SMTP plugin I've been using for some time is Easy WP SMTP by wpecommerce (https://wordpress.org/plugins/easy-wp-smtp/) and the alternative I tried this morning was WP Mail SMTP by WPForms (https://wordpress.org/plugins/wp-mail-smtp/).
The code I tried out in my functions file was this. I'd be keen to use this instead of a plugin to be honest but nervous about my email log in details being in it.
add_action( 'phpmailer_init', 'send_smtp_email' );
function send_smtp_email( $phpmailer ) {
// Define that we are sending with SMTP
$phpmailer->isSMTP();
// The hostname of the mail server
$phpmailer->Host = "smtp.gmail.com";
// Use SMTP authentication (true|false)
$phpmailer->SMTPAuth = true;
// SMTP port number - likely to be 25, 465 or 587
$phpmailer->Port = "465";
// Username to use for SMTP authentication
$phpmailer->Username = "EMAIL ASSOCIATED WITH GOOGLE ACCOUNT";
// Password to use for SMTP authentication
$phpmailer->Password = "PASSWORD";
// Encryption system to use - ssl or tls
$phpmailer->SMTPSecure = "ssl";
$phpmailer->From = "me@mydomain.com";
$phpmailer->FromName = "My Domain";
}
Thank you!
Okay after a bit more research I have a better understanding of how SMTP works now.
- CRED uses wp_mail to send email. When you use SMTP to send mail, it bypasses the standard wp_mail function and overrides the "from" email address specified by CRED.
- SMTP plugins like the two you have mentioned force you to define a "from" email address in their settings, or default to something like the site owner's email. CRED does not have a way to manipulate those settings.
- The code you added in PHP defines its own "from" email address, which CRED cannot control:
$phpmailer->From = "me@mydomain.com";
$phpmailer->FromName = "My Domain";
- Some SMTP servers allow changing the "from" email address to be something other than the login email address, others do not. Gmail does not, except in the case where you log in (this is the username and password you provide in the SMTP settings) using a Gmail account that is linked to multiple Gmail addresses. Then you can use any of the linked Gmail addresses. Regardless, the "from" email address is predetermined in your SMTP code or plugin settings.
So the short answer is, CRED has no control over the "from" email address when you use SMTP. I hope this helps. Let me know if you have any questions about that and I will do my best to get you some answers.
Hi Christian
Thank you for clarifying this.
If realistic, could we put forward a feature request for an option to set CRED forms to use SMTP please? Perhaps Toolset could write & integrate an SMTP plugin which could be activated & deactivated within Toolset with a built-in check on the CRED side of things so that different 'from' addresses could be used?
If this were available, I think this would add a huge amount of flexibility to CRED.
Many thanks
I can submit a feature request, though I'm not sure I understand how it would be manageable. Since you can use variables (shortcodes) in the "from" email address field, this means that you now need a way to manage SMTP accounts and relationships between SMTP accounts and the "to" email addresses that should be used with these SMTP accounts. What are your thoughts on how this would work?