Php 将自定义帖子类型字段发送到多封电子邮件
实际上,我想做的是向电子邮件发送自定义字段值 我已经创建了一个简单的表单,在post类型中,该表单只显示在前端,用户可以输入那里的电子邮件和电话号码。提交后,一封邮件发送给网站所有者,一封邮件发送给企业所有者,一封邮件发送给该特定用户的电子邮件id 这三封邮件都有不同的内容 现在的问题是Php 将自定义帖子类型字段发送到多封电子邮件,php,wordpress,forms,email,Php,Wordpress,Forms,Email,实际上,我想做的是向电子邮件发送自定义字段值 我已经创建了一个简单的表单,在post类型中,该表单只显示在前端,用户可以输入那里的电子邮件和电话号码。提交后,一封邮件发送给网站所有者,一封邮件发送给企业所有者,一封邮件发送给该特定用户的电子邮件id 这三封邮件都有不同的内容 现在的问题是 当我提交它时,每个人收到的邮件数量等于投递的数量 e、 g我有3个post项目&当我点击一个项目并提交时,它会发送所有项目的详细信息。我想限制它一个 网站所有者和企业所有者获得正确的信息,但最终用户无法获得自定
<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 = 'siteowner@site.com';
$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 = 'businessowner@business.co.in';
$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');
电子邮件的问题是因为电子邮件在一个循环中发送。这意味着它正在检查是否为每个循环设置了(isset($usermail)&&isset($cellno)){
,即帖子的数量
通过传入post ID并确认来修复此问题。
将当前帖子id添加到表单中:
<input type="hidden" name="postID" value="<?php echo $post_id; ?>">
使用get_field()
而不是the_field()
来正确分配变量。the
会回显它
即:
$phone = get_field('phone');
$pdesc = get_field('description');
电子邮件的问题是因为电子邮件在一个循环中发送。这意味着它正在检查是否为每个循环设置了(isset($usermail)&&isset($cellno)){
,即帖子的数量
通过传入post ID并确认来修复此问题。
将当前帖子id添加到表单中:
<input type="hidden" name="postID" value="<?php echo $post_id; ?>">