Skip to content

Commit

Permalink
Contact Form: remove www prefix from sender email address (#39370)
Browse files Browse the repository at this point in the history
On sites that use the www. prefix, there is no need to include that prefix in the default sender email address we generate before sending the emails.

Related discussion: https://wordpress.org/support/topic/wrong-domain-in-emails-sent-by-jetpack-2/
  • Loading branch information
jeherve authored Sep 12, 2024
1 parent 2461714 commit 5db2bb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Email submissions: on sites using www., ensure that the sending email address does not use the www. prefix.
13 changes: 11 additions & 2 deletions projects/packages/forms/src/contact-form/class-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,17 @@ public function process_submission() {
$to[ $to_key ] = self::add_name_to_address( $to_value );
}

$blog_url = wp_parse_url( site_url() );
$from_email_addr = 'wordpress@' . $blog_url['host'];
// Get the site domain and get rid of www.
$sitename = wp_parse_url( site_url(), PHP_URL_HOST );
$from_email_addr = 'wordpress@';

if ( null !== $sitename ) {
if ( str_starts_with( $sitename, 'www.' ) ) {
$sitename = substr( $sitename, 4 );
}

$from_email_addr .= $sitename;
}

if ( ! empty( $comment_author_email ) ) {
$reply_to_addr = $comment_author_email;
Expand Down

0 comments on commit 5db2bb3

Please sign in to comment.