Created
December 20, 2018 02:54
-
-
Save YuzuruSano/e2f0c8ed7a02f2a18d7e180629327a65 to your computer and use it in GitHub Desktop.
MW WP FORMでReply-toヘッダを指定する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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