簡體   English   中英

發送電子郵件到發布的電子郵件地址

[英]Send emails to posted email address

目前,我有一個目錄網站,對用戶到期通知。 我希望能夠將這些通知發送到目錄列表中的注冊電子郵件地址。 當前,該網站僅將電子郵件發送給post_author。

目錄頁面如下所示:

<code>$listing_type = get_post_meta($post->ID, 'geocraft_listing_type', true);
  $custom_meta = get_custom_field();
  foreach ($custom_meta as $meta):
  $field = $meta['name'];
  $title = $meta['title'];
  if ($meta['show_on_listing'] == 1) {
  if ($listing_type == 'free' && $meta['show_free'] == 'true') {
  if ($meta['type'] != 'image_uploader' && !in_array($field, $social_exclude)
  ) {
  if (get_post_meta($post->ID, $field, true)) {
  ?>
  <tr>
  <td class="label default"><?php echo $title; ?> </td>
  <td><?php
  if ($field == 'geocraft_website') {
  echo '<a target="new" href="' . get_post_meta($post->ID, $field, true) . '">' .              get_post_meta($post->ID, $field, true) . '</a>';
  } elseif ($field == 'geocraft_phone') {
  echo '<a href=tel:' . str_replace(' ', '', get_post_meta($post->ID, $field, true)) . '>' . str_replace(' ', '', get_post_meta($post->ID, $field, true)) . '</a>';
  } elseif ($field == 'geocraft_meta_email') {
  echo '<a href=mailto:' . get_post_meta($post->ID, $field, true) . '?Subject=subject here&Body=bodytext>' . get_post_meta($post->ID, $field, true) . '</a>';
  } elseif ($meta['type'] == 'multicheckbox') {
  echo implode(', ', get_post_meta($post->ID, $field, true));
  } else {
  echo get_post_meta($post->ID, $field, true);
  }
  ?></code>

我有以下過期通知代碼:

if ($expire == true && empty($is_expired)) {
$post_author = $listing->post_author;
$site_name = get_option('blogname');
$email = get_option('admin_email');
$website_link = get_option('siteurl');
$listing_title = $listing->post_title;
$lisgint_guid = $listing->guid;
$login_url = site_url("/wp-login.php?action=login");
$listing_user_name = get_the_author_meta('user_login', $post_author);
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Dear %s,", 'geocraft') . " \r", $listing_user_name);
$message .= __("Your listing is expired. We inform you that, if you are interested to reactivate your listing,", 'geocraft') . " \r";
$message .= __("Login in our website and reactivate it.", 'geocraft') . " \r";
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Listing Title: %s", 'geocraft') . " \r", $listing_title);
$message .= "Login On: $login_url \r";
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Website: %s", 'geocraft'), $site_name . "\r");
$message .= sprintf(__("Website URL: %s", 'geocraft'), $website_link . "\r");
$message .= "--------------------------------------------------------------------------------\r";

//$message1 .= "--------------------------------------------------------------------------------\r";
$message1 .= __("Dear Admin,", 'geocraft') . " \r\r";
$message1 .= __("A listing from one of your users got expired and a notification email has been sent to the user.", 'geocraft') . " \r\r";

$message1 .= __("Expired Listing Details are as follows:", 'geocraft') . " \r";
$message1 .= "--------------------------------------------------------------------------------\r";
$message1 .= sprintf(__("User Name: %s", 'geocraft') . " \r", $listing_user_name);
$message1 .= sprintf(__("Listing Title: %s", 'geocraft') . " \r", $listing_title);
$message1 .= "--------------------------------------------------------------------------------\r\r";
$message1 .= __("Kindly, Login to your site for more information:", 'geocraft') . " \r\r";
$message1 .= sprintf(__("Login On: %s", 'geocraft'), $login_url . "\r");
$message1 .= sprintf(__("Website: %s", 'geocraft'), $site_name . "\r");
$message1 .= "Website URL: $website_link\r";

//get listing author email
$to = get_the_author_meta('user_email', $post_author);
$subject = __('Your listing reactivation notice', 'geocraft');
$subject1 = __('Expired Listing notification', 'geocraft');
$headers = 'From: Site Admin <' . $email . '>' . "\r\n" . 'Reply-To: ' . $email;
if (empty($expired_listing)) {
$array = array();
update_option('gc_expired_listing', $array);
}
$expired_listing = (array) get_option('gc_expired_listing');
array_push($expired_listing, $listing->ID);
update_option('gc_expired_listing', $expired_listing);
//email to user
wp_mail($to, $subject, $message, $headers);
//email to admin
wp_mail($email, $subject1, $message1);
}
}

我知道我需要放置另一個wp_mail,但是我不知道如何定義該變量並向后工程數據庫PHP變量,因為我無權訪問它。

wp_mail($directoryEmail, $subject, $message, $headers);

任何幫助,將不勝感激。 抱歉,很長的帖子。 我是PHP的新手,也不想搞砸它,因為它可以向很多人發送電子郵件。

假設$listing是WP $post對象的格式,緊隨其后

$to = get_the_author_meta('user_email', $post_author);

$to .= ',' get_post_meta($listing->ID, 'geocraft_meta_email', true);

這樣,您就可以向兩個人發送一封電子郵件。 總共發送3封電子郵件會比較干凈,但是尚不清楚您是否可以訪問目錄列表人員的姓名。 您確實需要數據庫訪問權限才能執行此類工作。

為了確保您不會意外地向真實用戶發送電子郵件,請在進行任何更改之前,將整個網站復制到暫存/開發站點。 然后,您可以使用phpMyAdmin將geocraft_meta_email每個實例geocraft_meta_email為您自己的測試電子郵件地址。 我喜歡使用Gmail,因為如果您有一個類似於myname@gmail.com的地址,則可以通過電子郵件實際發送myname+anystringyoulike@gmail.com的電子郵件-這樣您仍會收到實際的電子郵件,但是它可以讓您准確地確定是哪封電子郵件通過了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM