将电子邮件发送到已发布的电子邮件地址

时间:2017-03-23 20:35:43

标签: php wordpress email

目前,我有一个到期通知用户的目录网站。我希望能够将这些相同的通知发送到目录列表中的注册电子邮件地址。目前,该网站仅将电子邮件发送给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新手,不想搞砸了,因为它可以给很多人发电子邮件。

1 个答案:

答案 0 :(得分:0)

假设$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的每个实例更改为您自己的测试电子邮件地址。我喜欢使用Gmail,因为如果您有myname@gmail.com这样的地址,您实际上可以发送电子邮件至myname+anystringyoulike@gmail.com - 这样您仍会收到实际的电子邮件,但它可以让您确切地确定通过哪个电子邮件。< / p>