Invalid address (setFrom)
-
When I have the following plugins active…
- Mailgun
- WooCommerce
- WooCommerce PDF Invoices & Packing Slips
- WP Mail Logging (debugging purposes)
Then neither my automated nor triggered Woocommerce Order emails with attachments go through. WP Mail Logging gives me the error: “Invalid address (setFrom) [email protected]” [Obviously, the actual address is valid.]
I have the plugin set to attach invoices to: New Order (admin email), Processing order, Completed Order, Refunded order, Customer invoice / Order details (manual email). None of these work. HOWEVER, Customer note (which is not selected) does still work. This seems to be a plugin conflict between you and Mailgun.
Any ideas?
-
Hello Joe,
We recently had another customer report this “Invalid address (setFrom) [email protected]” error they found in WP Mail Logging. I looked through the WP Mail Logging issues and only found this: Fatal error: Uncaught phpmailerException: Invalid address: (setFrom) and I’m not sure if it’s related… Our plugin doesn’t actually send the email (let alone define the “from:” address), this is entirely handled by WooCommerce. Our plugin merely tells WooCommerce to include our PDF as attachment.The only thing I can think of is:
- Have you set up a filter to send a CC or BCC copy of the email? (from the documentation). That may be interfering here.
- Or… the error given is not what’s actually the issue.
Did you test without Mailgun, and if not, could you try that? Just make sure whether that’s indeed the conflict here.
here’s another possibly related issue in WP Mail Logging: #80. Not saying it’s a WP Mail Logging issue, but it may provide hints on the actual issue at hand. I assume that you are not ‘resending’ anything from WP Mail Logging?
Ewout,
Thank you for the reply. I agree with you that the error message WP Mail Logging is providing is not helpful and likely not accurate. However, the issue it not with WP Mail Logging – the issue was occurring before I installed it; I installed it merely to try and identify some patterns. (I’m also not using resending.)
There are also no PDF Invoice filters at play that I am aware of.
When I unchecked all email attachments, there are no errors and mail goes through as expected.
When invoice attachments are activated, mail fails somewhere within either WooCommerce or WP proper. The mail never makes it out of my server to the Mailgun servers (as indicated by their logs.) However, Woocommerce thinks it is successful and does not return an error message.
I just triple checked and it is almost certainly a plugin conflict between Mailgun and PDF Invoices (in the context of Woocommerce).
To recap, the only time the issue is present is under the following circumstances
- All 3 plugins are active and properly configured: Woocommerce, PDF Invoices, Mailgun
- Invoice attachments are set for Woocommerce Mail
- Mail is triggered involving one of the attachments.
Has there been some sort of update lately to the way WordPress handles attachments? This used to work perfectly fine with the aforementioned set up.
-
This reply was modified 5 years, 10 months ago by
Joe G..
Thanks for the detailed response. I don’t have Mailgun which makes it harder to find the root cause of this issue… Looking at the Mailgun plugin code I see that there is apparently an option to use the API or use SMTP. Which are you using? The code here mentions something about the from address:
// Either override the wp_mail function or configure PHPMailer to use the
// Mailgun SMTP servers
// When using SMTP, we also need to inject awp_mail
filter to make “from” settings
// work properly. Fixes issues with 1.5.7+That particular filter is here:
includes/wp-mail-smtp.php#L87-L149There’s quite a bit going on there, but it’s quite strange to me how adding an attachment would ever interfere with the from address. Especially if you mention that not adding the attachment makes the email send fine. My guess is that the mg_parse_headers() function is tripping on the attachments somewhere, but that’s not more than a first idea at this point.
You could try switching that SMTP/API option in the Mailgun settings, to see if that helps.
I’m not aware of any recent changes in WP/WooCommerce itself with regards to the emailing process.
Have you contacted Mailgun support about this?
-
This reply was modified 5 years, 10 months ago by
Ewout. Reason: mailgun settings suggestion
I am using SMTP. I’ll have to dig into that a little more… It is a complicated issue!
I’m skeptical about the “from” failure that WP Mail Logging is giving. It might be something else? I agree that it’s proabbly some sort of header check somewhere. Can you provide an example of what a normal Woocommerce Email header w/ PDF attachment should look like?
I also have a ticket open with Mailgun. I’ll see what they say.
I am using SMTP
If I am reading the Mailgun code correctly, using the API instead would bypass this issue.
I’m skeptical about the “from” failure that WP Mail Logging is giving. It might be something else?
I’m not sure either, but I think WP Mail Logging is simply catching an error from
PHPMailer
. I doubt that PHPMailer would throw such a specific error if the error is not with the from address.
If my analysis is correct, Mailgun plugin is running logic on the headers to determine the from address they are overriding when SMTP is activated, and with an attachment being present, this is going haywire somewhere and it is not applying the correct ‘from’ address… Or the mg_dump_headers() function is messing up when an attachment is present.I’m sorry if this isn’t helpful, as mentioned I don’t have Mailgun which makes it hard to debug. Looking forward to hearing Mailgun’s reaction!
I tried to run some tests today but not having a Mailgun account isn’t helping much. Could you tell me a bit more about your Mailgun settings?
- Use HTTP API
- Override “From” Details
If you have enable the Override, is the setFrom error showing that, or does it show the email address set in WooCommerce > Settings > Emails > Email sender options?
@webgmclassics, I had another customer with this issue and we pinned it down to a possible bug with PHP7.3, Downgrading to PHP7.2 resolved the issue. We are investigating further on the possible causes and how we can fix/prevent this.
Have you moved to another solution or is this still an issue for you? Can you confirm that downgrading to PHP7.2 resolves the issue for you too?
Hi Ewout,
The only way I was able to get it to work was to uncheck the pdf invoice attachment option. Since doing that, I have not had any issues. But, it still does not work with attachments. I am using PHP 7.3. I am still using your plugin.
Unfortunately, downgrading to 7.2 is not an option for us. I can test it on a staging environment later, but it’ll take a couple weeks to get through my to-do list first.
If you need to test on your end, Mailgun accounts are free as long as you don’t go over a very generous quota. Try it it out and see if you can come up with something. I’ll let you know if I find out anything further.
What we found was that it wasn’t actually related to Mailgun per se, there were others with this same issue using the default WordPress mailer.
Today I did a few additional tests I was able to narrow down exactly where this failed. Why it fails with the attachment and not without is beyond me, this appears to be a bug in PHP somewhere.
Here’s what I found:
Depending on the PHP version and installed extensions, PHPMailer selects a service/function to validate an email address. In the case of PHP7.3, this is usually ‘pcr8‘, and the address failed this verification. Newer versions of PHPMailer (WordPress bundles an older version by default because they need compatibility with older PHP versions) actually default to a different validation service built into PHP usingfilter_var($address, FILTER_VALIDATE_EMAIL)
.
I used a code snippet to change the validation service for PHPMailer in WordPress:add_filter( 'wp_mail', function( $mailArray ) { global $phpmailer; if ( ! ( $phpmailer instanceof PHPMailer ) ) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer( true ); } $phpmailer::$validator = 'php'; return $mailArray; } );
Could you try adding this code snippet to your site to see if that resolves the issue for you too? If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters
@webgmclassics could you also let us know the exact version + distro (if included) of PHP you are using (i.e. 7.3.4-1+ubuntu16.04.1+deb.sury.org+3)
Server architecture Linux 4.15.0-1028-gcp x86_64
Web server nginx/1.15.12
PHP version 7.3.4-1+ubuntu16.04.1+deb.sury.org+3 (Supports 64bit values)
PHP SAPI fpm-fcgiThanks so much for sharing! That makes it more likely this is distro related (I’ve had two other people confirm this issue with
ubuntu16.04.1+deb.sury.org
), and also quite likely that the above snippet will fix the issue.We released version 2.2.14 today which includes the above
wp_mail
filter for PHP7.3 installations. Based on reports from other users I believe this should fix the setFrom error in PHPMailer. Let us know if the problem persists!This may have been an issue. It took me some time to track this down, but your thread here pointed me in the right direction.
In short, there is a bug in the older versions of the PCRE library used by PHP 7.3 that causes WP’s email address regex validator to fail. PHP 7.2 and under use a different PCRE library than does 7.3
https://gist.github.com/yolabingo/68b4f037661e702742c5abb324a3d992
- The topic ‘Invalid address (setFrom)’ is closed to new replies.