2014-12-07 111 views
0

我正嘗試在wordpress上設置一個帶有插件的登陸頁面 - 即將推出CC。它有一個訂閱框。每次有人註冊時事通訊時,我都會收到來自[email protected]的電子郵件。我怎樣才能以訂閱者的郵件標識本身而不是[email protected]獲取郵件的方式進行更改。換句話說,它可以從訂閱者的電子郵件標識而不是wp_mail中獲取併發送郵件。 這是我在插件文件中找到 -如何將wp_mail更改爲訂閱者電子郵件ID

/** 
* [ajax_newsletter_subscribe description] 
* @return [type] [description] 
*/ 
public function ajax_newsletter_subscribe() { 

    check_ajax_referer('cc-cs-newsletter-subscribe'); 

    $to_email = $this->get_option('newsletter', 'email') ? $this->get_option('newsletter', 'email') : get_option('admin_email'); 

    if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { 

     $sent = wp_mail(
      $to_email, 
      __('You have a new subscriber!', $this->plugin_slug), 
      sprintf(__("Hello,\n\nA new user has subscribed through your Coming Soon page.\n\nSubscriber's email: %s", $this->plugin_slug), $_POST['email']) 
     ); 

     if($sent) { 
      print json_encode(array('status' => 'ok')); 
      die(); 
     } 
    } 

    print json_encode(array('status' => 'error')); 
    die(); 
} 

回答

0

您可以設置電子郵件$headers,其中From

$headers = array(); 
$headers[] = 'From: ' . $_POST['email'] . ' <' . $_POST['email'] . '>'; 

$sent = wp_mail(
    $to_email, 
    __('You have a new subscriber!', $this->plugin_slug), 
    sprintf(__("Hello,\n\nA new user has subscribed through your Coming Soon page.\n\nSubscriber's email: %s", $this->plugin_slug), $_POST['email']), 
    $headers 
); 

檢查Codex

+0

嘿diggy,感謝您的答覆。對不起,我有點新的編碼,你能幫我什麼,我應該放在'從',所以它提取訂閱者電子郵件ID本身? – Abhilash 2014-12-08 04:04:57

+0

更新了答案 – diggy 2014-12-08 18:54:04