Make WordPress Core

Opened 7 years ago

Closed 7 months ago

Last modified 7 months ago

#46217 closed defect (bug) (worksforme)

wp_mail() not sending messages on PHP7.3.x

Reported by: whatevs's profile whatevs Owned by:
Milestone: Priority: normal
Severity: major Version: 5.0.3
Component: Mail Keywords:
Focuses: Cc:

Description

Hi,

I believe that this is a bug but my PHP-fu is not yet the belt color needed to further debug and fix this.
I have tested this behavior on WordPress 5.0.3 and GitHub sources from 2019-02-07, on FreeBSD and Linux Ubuntu 18.04, with PHP 7.3.1.
PHP versions 7.2 and older work as expected.

While PHP's mail() sends e-mails flawlessly, there are no attempts to open connection to a SMTP server when using wp_mail().

This issue covers all WordPress e-mails including the initial "New WordPress Site" message. Example code, working on PHP 7.2 but not on 7.3.

<?php
require('./wp-config.php');
$headers = 'From: whatevs <tester@proper-and-existing-domain.net>' . "\r\n";
wp_mail('something@proper-and-existing-domain.com','wp mail test','test test test', $headers );

The above example works with PHP 7.3 when "wp_mail" is replaced with "mail". 3rd party PHPmailer also works on PHP 7.3 with no issues.

Upon testing this behavior with tcpdump I can see that with PHP 7.2, WordPress opens a connection to 127.0.0.1:25 and tries to send the message. With PHP 7.3 there are no attempts to establish such connection on lo interface nor any other.

The following change results in: "Invalid address: (setFrom) tester@…"

--- wp-includes/pluggable.php	2019-02-08 15:37:38.459579000 +0100
+++ wp-includes/pluggable.php-debug	2019-02-08 15:37:29.683718000 +0100
@@ -364,7 +364,8 @@
 			$mail_error_data['phpmailer_exception_code'] = $e->getCode();

 			/** This filter is documented in wp-includes/pluggable.php */
-			do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
+			//do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
+			print('DEBUG '.$e->getMessage().' DEBUG');
 			return false;
 		}

Change History (6)

#1 @techsurgeons
7 years ago

We're seeing this too. Haven't dug in to try and find the specific change yet.

#2 @stefahn
7 years ago

  • Severity changed from normal to major

This affects the Divi contact form for example. It does not send a mail to the admin after a visitor filled out the form.

The problem is: nobody gets an error message. So the visitor thinks the message is delivered but it is not. And the admin does not see that there is something wrong (even in php_error.log I didn't see anything).

I thus changed the severity to "major".

#3 @racosgrave
7 years ago

I am experiencing a similar issue using WP 5.2.1, PHP 7.0.33-0ubuntu0.16.04.4, Easy WP SMTP Version 1.3.9.1.

BBPress notifications come out from the system fine, Test Emails from Easy WP SMTP works fine, however when I call wp_mail() from one of my scripts (has been working fine) I now get an error like 'Invalid address: (setFrom) wordpress@' when I look at WP Mail Log.

Previously I only had Content Type in the header, then did not specify any extra headers to wp_mail() which didnt work either. Only by setting the From: manually in the code (like I have redunantly in Easy WP SMTP) in the header and add that to wp_mail() does it actually work again.

#4 follow-up: @netzgestaltung
6 years ago

Hi, i also do have this issue:

With PHP 7.3 on, this test script at page.php fails:

<?php

    if ( $_GET['testmail'] === "1" ) {
      ini_set( 'display_errors', 1 );
      error_reporting( E_ALL );
      
      // define the wp_mail_failed callback 
      function action_wp_mail_failed($wp_error){
        echo var_dump($wp_error);
      }
      add_action('wp_mail_failed', 'action_wp_mail_failed', 10, 1);
      
      $from = "wordpress@alphabetisierung.at";
      $recipient = "listing@majors-welt.net";
      $subject = "PHP Mail Test script";
      $body = "This is a test to check the PHP Mail functionality";
      $headers = "From: " . $from . "\r\n";
      $mail = wp_mail( $recipient, $subject, $body, $headers );
      if ( $mail ) {
        wp_die('mail sendt');
      } else {
        wp_die('mail not sendt');
      }
    }
object(WP_Error)#10509 (2) {
  ["errors"]=>
  array(1) {
    ["wp_mail_failed"]=>
    array(1) {
      [0]=>
      string(57) "Invalid address:  (setFrom) wordpress@alphabetisierung.at"
    }
  }
  ["error_data"]=>
  array(1) {
    ["wp_mail_failed"]=>
    array(6) {
      ["to"]=>
      array(1) {
        [0]=>
        string(23) "listing@majors-welt.net"
      }
      ["subject"]=>
      string(20) "PHP Mail Test script"
      ["message"]=>
      string(50) "This is a test to check the PHP Mail functionality"
      ["headers"]=>
      array(0) {
      }
      ["attachments"]=>
      array(0) {
      }
      ["phpmailer_exception_code"]=>
      int(0)
    }
  }
}

When switching the servers PHP version to 7.2-latest the email gets send

WP: 5.3–de_DE

kind regards
tom

#5 in reply to: ↑ 4 @SirLouen
7 months ago

  • Keywords needs-testing removed
  • Resolution set to worksforme
  • Status changed from new to closed

Reproduction Report

Description

❌ This report can't validate that the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.0
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 138.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins: None activated
  • Plugins:
    • Testing Dolly
    • Test Reports 1.2.0

Testing Instructions

  1. I've set up a local mail server in port 1025
  2. Used the exact code provided in comment 4
  3. ❌ Tested running the code, email was delivered

Actual Results

  1. ❌ Error condition is not occurring

Additional Notes

  • Long time has passed since this was reported without answers. But it seems its not reproducible anymore

First I've tested this version:

Replying to netzgestaltung:

Hi, i also do have this issue:

With PHP 7.3 on, this test script at page.php fails:

<?php

    if ( $_GET['testmail'] === "1" ) {
      ini_set( 'display_errors', 1 );
      error_reporting( E_ALL );
      
      // define the wp_mail_failed callback 
      function action_wp_mail_failed($wp_error){
        echo var_dump($wp_error);
      }
      add_action('wp_mail_failed', 'action_wp_mail_failed', 10, 1);
      
      $from = "wordpress@alphabetisierung.at";
      $recipient = "listing@majors-welt.net";
      $subject = "PHP Mail Test script";
      $body = "This is a test to check the PHP Mail functionality";
      $headers = "From: " . $from . "\r\n";
      $mail = wp_mail( $recipient, $subject, $body, $headers );
      if ( $mail ) {
        wp_die('mail sendt');
      } else {
        wp_die('mail not sendt');
      }
    }

Obviously firstly initializing some server for delivery (I don't have locally configured mail function with a local MTA server, so I can't make direct use of it, but for testing purposes this is irrelevant).

<?php

function initialize_mail_server( $phpmailer ) {
        $phpmailer->isSMTP();
        $phpmailer->Host = 'localhost';
        $phpmailer->Port = 1025;
}
add_action( 'phpmailer_init', 'initialize_mail_server' );

And the mail is going through perfectly

I'm wondering about this error:
string(57) "Invalid address: (setFrom) wordpress@alphabetisierung.at"

It was clearly PHPMailer error, not related with wp_mail directly, more specifically triggered under these circumstances.

But, as I say with current PHP version, PHPMailer version and WP version its not reproducible anymore. So it's time to close this ticket as worksforme. Feel free to reopen it or comment back, if you think you have newer instructions to reproduce this

#6 @peterwilsoncc
7 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.