发送自定义帖子类型字段到多个邮件
问题描述:
其实我想要做的是我想发送自定义字段值到电子邮件。发送自定义帖子类型字段到多个邮件
我已经创建了一个简单的帖子类型的表单,只显示在这个表单前端用户可以输入那里的电子邮件和电话号码。在提交一封邮件到网站所有者之后,一封邮件将发送给企业主,一封邮件将发送给该特定用户的电子邮件ID。
所有三个邮件具有不同的内容
现在的问题是
当我提交了没有。每个收到的邮件等于没有。的帖子 例如我有3个帖子项目&当我点击一个项目并提交时,它发送所有项目的详细信息。我想限制一个。
网站所有者和业主获取正确的信息,但最终用户无法获得自定义字段值,自定义字段来自高级自定义字段插件。
有没有人可以解决这些问题。
感谢
下面是代码
<div class="column one">
<?php $pack= new WP_Query(array('post_type'=>'packer'));?>
<?php while($pack-> have_posts()): $pack->the_post();?>
<?php
$post = get_post($post);
$title = isset($post->post_title) ? $post->post_title : '';
$usermail=$_POST['email'];
$cellno=$_POST['cellno'];
$phone=the_field('phone');
$pdesc=the_field('description');
if(isset($usermail) && isset($cellno)){
$to = '[email protected]';
$subject = 'New Enqiry for'. $title;
$body ="The enquiry for $title <br>Customer email is: $usermail<br> Customer Phone is: $cellno";
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $body, $headers);
$to = '[email protected]';
$subject = 'New Customer Enquiry';
$body ="The enquiry by $usermail <br>Cellno is: $cellno";
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $body, $headers);
$to = $usermail;
$subject = 'Details For $title';
$body ="Phone $phone <br>Desc is: $pdesc";
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $body, $headers);
}
?>
<div class="column one-fourth">
<h1><?= the_title();?></h1>
<?php $post_id= get_post()->ID;?>
<img src="<?php the_field('logo');?>" />
<a href="#desc-<?= $post_id;?>" class="fancybox">
<input type="button" name="Details" value="DON'T PRESS THIS BUTTON"/>
</a>
<div style="display:none" class="fancybox-hidden">
<div id="desc-<?= $post_id;?>">
<?php the_field('description');?>
<?php the_field('phone');?>
<form action="" method="POST">
<input type="text" placeholder="Phone" name="cellno" id="cellno">
<input type="email" placeholder="Email" name="email" id="email">
<input type="submit" value="Send" name="send" id="send">
</form>
</div>
</div>
</div>
<?php endwhile; ?>
答
使用get_field()
而不是the_field()
正确地分配变量。 the_
呼应它。
即:
$phone = get_field('phone');
$pdesc = get_field('description');
问题与电子邮件,是因为你的电子邮件在一个循环中发送。这意味着它的检查是为每个循环设置if(isset($usermail) && isset($cellno)){
,也就是帖子的数量。
通过传递帖子ID并确认,解决此问题。 当前POST_ID添加到您的窗体:
<input type="hidden" name="postID" value="<?php echo $post_id; ?>">
并检查它是否等于在循环中目前职位ID。
if(isset($usermail) && isset($cellno) && isset($_POST['postID']) && $_POST['postID'] == $post->ID){
非常感谢@ jacob-raccuia它的工作! :) –