Directory

Mail: allow custom attachment filenames in `wp_mail()`. · WordPress/WordPress@0f0646e · GitHub
Skip to content

Commit

Permalink
Mail: allow custom attachment filenames in wp_mail().
Browse files Browse the repository at this point in the history
Previous to this change, attachment filenames in outgoing emails could only ever be derived from their paths (passed in as a numerically indexed array of `$attachments`).

This changeset adds support for passing an associative `$attachments` array, where the key strings will be used as filenames instead.

Includes 2 new unit tests to ensure both array formats continue to work as intended.

Props johnjamesjacoby, ritteshpatel, swissspidy, syntaxart.
Fixes #28407.
Built from https://develop.svn.wordpress.org/trunk@55030


git-svn-id: http://core.svn.wordpress.org/trunk@54563 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
JJJ committed Jan 5, 2023
1 parent 995964e commit 0f0646e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,11 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
}

if ( ! empty( $attachments ) ) {
foreach ( $attachments as $attachment ) {
foreach ( $attachments as $filename => $attachment ) {
$filename = is_string( $filename ) ? $filename : '';

try {
$phpmailer->addAttachment( $attachment );
$phpmailer->addAttachment( $attachment, $filename );
} catch ( PHPMailer\PHPMailer\Exception $e ) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-55029';
$wp_version = '6.2-alpha-55030';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 0f0646e

Please sign in to comment.