Skip to content

Commit

Permalink
Reply to field (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-mykhailenko authored Jul 26, 2024
1 parent d24b632 commit e8ca032
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public function ajax_send_test()
$useAPI = (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI) ? MAILGUN_USEAPI : $this->get_option('useAPI');
$secure = (defined('MAILGUN_SECURE') && MAILGUN_SECURE) ? MAILGUN_SECURE : $this->get_option('secure');
$sectype = (defined('MAILGUN_SECTYPE') && MAILGUN_SECTYPE) ? MAILGUN_SECTYPE : $this->get_option('sectype');
$replyTo = (defined('MAILGUN_REPLY_TO_ADDRESS') && MAILGUN_REPLY_TO_ADDRESS) ? MAILGUN_REPLY_TO_ADDRESS : $this->get_option('reply_to');

if (!$getRegion) {
mg_api_last_error(__("Region has not been selected", "mailgun"));
Expand Down Expand Up @@ -448,12 +449,17 @@ public function ajax_send_test()
}

try {
$headers = [
'Content-Type: text/plain',
'Reply-To: ' . $replyTo,
];

$result = wp_mail(
$admin_email,
__('Mailgun WordPress Plugin Test', 'mailgun'),
sprintf(__("This is a test email generated by the Mailgun WordPress plugin.\n\nIf you have received this message, the requested test has succeeded.\n\nThe sending region is set to %s.\n\nThe method used to send this email was: %s.",
'mailgun'), $region, $method),
['Content-Type: text/plain']
$headers
);
} catch (Throwable $throwable) {
//Log purpose
Expand Down
21 changes: 21 additions & 0 deletions includes/options-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
$mailgun_from_address_const = ((defined('MAILGUN_FROM_ADDRESS') && MAILGUN_FROM_ADDRESS) ? MAILGUN_FROM_ADDRESS : null);
$mailgun_from_address = $mailgun_from_address_const ?: $this->get_option('from-address');

$mailgunReplyToAddressConst = ((defined('MAILGUN_REPLY_TO_ADDRESS') && MAILGUN_REPLY_TO_ADDRESS) ? MAILGUN_REPLY_TO_ADDRESS : null);
$mailgunReplyTo = $mailgunReplyToAddressConst ?: $this->get_option('reply_to');

$mailgun_secure_const = (defined('MAILGUN_SECURE') ? MAILGUN_SECURE : null);
$mailgun_secure = !is_null($mailgun_secure_const) ? ((string)(1 * $mailgun_secure_const)) : $this->get_option('secure');

Expand Down Expand Up @@ -318,6 +321,24 @@ class="regular-text"
</p>
</td>
</tr>
<tr>
<th scope="row">
<?php _e('Reply To Address', 'mailgun'); ?>
</th>
<td>
<input type="text"
class="regular-text"
name="mailgun[reply_to]"
value="<?php esc_attr_e($mailgunReplyTo); ?>"
placeholder="[email protected]"
/>
<p class="description">
<?php
_e('Reply-to address', 'mailgun');
?>
</p>
</td>
</tr>
<tr valign="top">
<th scope="row">
<?php _e('From Name', 'mailgun'); ?>
Expand Down
5 changes: 5 additions & 0 deletions includes/wp-mail-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = [])
}
}

$replyTo = (defined('MAILGUN_REPLY_TO_ADDRESS') && MAILGUN_REPLY_TO_ADDRESS) ? MAILGUN_REPLY_TO_ADDRESS : get_option('reply_to');
if (!empty($replyTo)) {
$headers['Reply-To'] = $replyTo;
}

// Set custom headers
if (!empty($headers)) {
foreach ((array)$headers as $name => $content) {
Expand Down
3 changes: 3 additions & 0 deletions languages/mailgun-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,6 @@ msgstr ""
#: includes/options-page.php:74
msgid "Save Changes"
msgstr "Änderungen speichern"

msgid "Reply-to address"
msgstr "Antwortadresse"
3 changes: 3 additions & 0 deletions languages/mailgun-es_ES.po
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,6 @@ msgstr ""
#: includes/options-page.php:74
msgid "Save Changes"
msgstr "Guardar cambios"

msgid "Reply-to address"
msgstr "dirección de respuesta"
3 changes: 3 additions & 0 deletions languages/mailgun-pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,6 @@ msgstr ""
#. Author URI of the plugin/theme
msgid "http://www.mailgun.com/"
msgstr ""

msgid "Reply-to address"
msgstr ""
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ MAILGUN_FROM_NAME Type: string
MAILGUN_FROM_ADDRESS Type: string
MAILGUN_TRACK_CLICKS Type: string Choices: 'yes' or 'no'
MAILGUN_TRACK_OPENS Type: string Choices: 'yes' or 'no'
MAILGUN_REPLY_TO_ADDRESS Type: string
```

- What hooks are available for use with other plugins?
Expand Down

0 comments on commit e8ca032

Please sign in to comment.