Skip to content

Instantly share code, notes, and snippets.

@YuzuruSano
Created December 20, 2018 02:54
Show Gist options
  • Save YuzuruSano/e2f0c8ed7a02f2a18d7e180629327a65 to your computer and use it in GitHub Desktop.
Save YuzuruSano/e2f0c8ed7a02f2a18d7e180629327a65 to your computer and use it in GitHub Desktop.
MW WP FORMでReply-toヘッダを指定する
<?php
//xxxはMW WP FORMのフォームIDを入れる
add_action('mwform_before_send_admin_mail_mw-wp-form-xxx', function ($Mail_admin, $Data) {
add_filter('wp_mail', function($param) use ($Data){
$data = $Data->gets();
if(isset($param['to'])){
//管理者と閲覧者でReply-To設定を分けたい場合はメールアドレスの文字列で判定
//下記はサンプルでtoに含まれるドメインで判定
preg_match('/mydomain\.jp/', $param['to'],$match);
if(count($match) > 0){
$email = $data['email'];//'email'はReply-Toに入れたいメールアドレスのキー。適宜変更
$name = $data['name'];//'name'はReply-Toに入れたい差出人名のキー。適宜変更
$param['headers'][] = 'Reply-To: "'.$name.'" <'.$email.'>';//ここでメールヘッダに追加
}
}
return $param;
}, 10, 1);
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment