Skip to content

Commit 90a32ec

Browse files
Add option to force the from email
1 parent 5e987dd commit 90a32ec

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

page-settings.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
<?php if ( isset( $this->overridden_settings['sender_address'] ) ) : ?>
5454
<div class="notice notice-info"><code>POSTMARK_SENDER_ADDRESS</code> is defined in your wp-config.php and overrides the <code>Sender Email</code> set here.</div>
5555
<?php endif; ?>
56+
57+
<?php if ( isset( $this->overridden_settings['sender_address'] ) ) : ?>
58+
<div class="notice notice-info"><code>POSTMARK_FORCE_FROM</code> is defined in your wp-config.php and overrides the <code>Force From</code> set here.</div>
59+
<?php endif; ?>
5660

5761
<div class="tab-content tab-general">
5862
<table class="form-table">
@@ -84,6 +88,13 @@
8488
<div class="footnote">This email must be a verified <a href="https://account.postmarkapp.com/signatures" target="_blank">Sender Signature</a>. It will appear as the "from" address on all outbound emails.</div>
8589
</td>
8690
</tr>
91+
<tr>
92+
<th><label>Force Sender Email</label></th>
93+
<td>
94+
<input type="checkbox" class="pm-force-from" value="1" />
95+
<span class="footnote">Force emails to be sent from the Sender Email specified above. Disallows overriding using the <code>$headers</code> array.</span>
96+
</td>
97+
</tr>
8798
<tr>
8899
<th><label>Force HTML</label></th>
89100
<td>
@@ -145,7 +156,7 @@
145156
<pre>
146157
$headers = array();
147158

148-
// Override the default 'From' address
159+
// Override the default 'From' address if 'Force Sender Email' is not enabled
149160
$headers['From'] = '[email protected]';
150161

151162
// Send the message as HTML

postmark-settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'api_key' => defined( 'POSTMARK_API_KEY' ) ? POSTMARK_API_KEY : null,
1111
'stream_name' => defined( 'POSTMARK_STREAM_NAME' ) ? POSTMARK_STREAM_NAME : null,
1212
'sender_address' => defined( 'POSTMARK_SENDER_ADDRESS' ) ? POSTMARK_SENDER_ADDRESS : null,
13+
'force_from' => defined( 'POSTMARK_FORCE_FROM' ) ? POSTMARK_FORCE_FROM : null,
1314
);
1415
$settings_from_constants = array_filter( $settings_from_constants );
1516
$settings = array_merge( $settings, $settings_from_constants );

postmark.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function load_settings() {
8181
'api_key' => get_option( 'postmark_api_key', '' ),
8282
'stream_name' => get_option( 'postmark_stream_name', 'outbound'),
8383
'sender_address' => get_option( 'postmark_sender_address', '' ),
84+
'force_from' => get_option( 'postmark_force_from', 0 ),
8485
'force_html' => get_option( 'postmark_force_html', 0 ),
8586
'track_opens' => get_option( 'postmark_trackopens', 0 ),
8687
'track_links' => get_option( 'postmark_tracklinks', 0 ),
@@ -103,6 +104,12 @@ public function load_settings() {
103104
update_option( 'postmark_settings', wp_json_encode( $settings ) );
104105
return $settings;
105106
}
107+
108+
if ( is_array( $settings ) && ! isset( $settings['force_from'] ) ) {
109+
$settings['force_from'] = 0;
110+
update_option( 'postmark_settings', wp_json_encode( $settings ) );
111+
return $settings;
112+
}
106113

107114
return json_decode( $settings, true );
108115
}
@@ -275,6 +282,13 @@ public function save_settings() {
275282
} else {
276283
$settings['sender_address'] = '';
277284
}
285+
286+
// We validate that 'force_from' is a numeric boolean.
287+
if ( isset( $data['force_from'] ) && 1 === $data['force_from'] ) {
288+
$settings['force_from'] = 1;
289+
} else {
290+
$settings['force_from'] = 0;
291+
}
278292

279293
// We validate that 'force_html' is a numeric boolean.
280294
if ( isset( $data['force_html'] ) && 1 === $data['force_html'] ) {

wp-mail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
153153
// Allow overriding the From address when specified in the headers.
154154
$from = $settings['sender_address'];
155155

156-
if ( isset( $recognized_headers['From'] ) ) {
156+
if ( false === $settings['force_from'] && isset( $recognized_headers['From'] ) ) {
157157
$from = $recognized_headers['From'];
158158
}
159159

0 commit comments

Comments
 (0)