【问题标题】:Send emails to posted email address将电子邮件发送到已发布的电子邮件地址
【发布时间】:2017-03-24 05:00:11
【问题描述】:

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

【问题讨论】:

  • 网站是 www.roofingcompaniesomahane.com

标签: php wordpress email


【解决方案1】:

假设 $listing 是 WP $post 对象的格式,紧随其后

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

添加

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

这样,您将一封电子邮件发送给两个人。总共发送 3 封单独的电子邮件会更简洁,但尚不清楚您是否有权访问列出人员姓名的目录。您确实需要数据库访问权限才能完成此类工作。

为确保您不会意外向真实用户发送电子邮件,在您进行任何更改之前,请将您的整个网站复制到一个临时/开发网站。然后,您可以使用 phpMyAdmin 将 geocraft_meta_email 的每个实例更改为您自己的测试电子邮件地址。我喜欢使用 Gmail,因为如果你有一个像 myname@gmail.com 这样的地址,你实际上可以通过电子邮件发送 myname+anystringyoulike@gmail.com - 这样你仍然会收到实际的电子邮件,但它可以让你准确地识别出是哪封电子邮件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    • 2017-03-01
    • 2014-04-27
    相关资源
    最近更新 更多