Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过第2部分发送用户数据_Php_Wordpress_Forms - Fatal编程技术网

Php 通过第2部分发送用户数据

Php 通过第2部分发送用户数据,php,wordpress,forms,Php,Wordpress,Forms,我正在寻求更多关于如何处理这一问题的建议 我有一个网页链接到每个管理员成员,点击后,他们的显示名称。在第二个页面(表单)上,它采用显示名称,并用其显示名称填充主题字段。我也需要抓取与该用户关联的电子邮件地址,但将其用作第二页表单发送到的电子邮件地址,因为当前我的脚本只能将其发送到我硬编码到其中的电子邮件地址 第一页是: <?php $args1 = array( 'role' => 'committee', 'orderby' => 'user_nicename', 'o

我正在寻求更多关于如何处理这一问题的建议

我有一个网页链接到每个管理员成员,点击后,他们的显示名称。在第二个页面(表单)上,它采用显示名称,并用其显示名称填充主题字段。我也需要抓取与该用户关联的电子邮件地址,但将其用作第二页表单发送到的电子邮件地址,因为当前我的脚本只能将其发送到我硬编码到其中的电子邮件地址

第一页是:

<?php
$args1 = array(
 'role' => 'committee',
 'orderby' => 'user_nicename',
 'order' => 'ASC'
);
 $committee = get_users($args1);


foreach ($committee as $user) {
echo ' 

    <a href="../contact-form?displayname=' . $user->display_name . '"><b style="font-size:18px;">
    <tr>
        <td style="padding: 10px;">' .$user->job_title .' - </td>
        <td style="padding: 10px;">' .$user->display_name .'</td>
    </tr></b></a><br><br>';

 }

?>

第二页是:

<?php $displayname = $_GET['displayname'];?>

<form role="form" method="post" action="../mailuser.php">  

<div class="form-group">

<input type="hidden" name="displayname" value="<?php echo $displayname ?>">
<input type="text" name="hp" class="hp" value="" alt="if you fill this field out then your email will not be sent">

</div>


<div class="form-group">
<label for="InputName">Your name</label>
<input type="name" class="form-control" id="InputName" placeholder="Enter your name" name="username">
</div>

<div class="form-group">                      
<label for="InputEmail">Email address</label>
<input type="email" class="form-control" id="InputEmail" placeholder="you@example.com" name="emailFrom">
</div>

<div class="form-group">                             
<label for="InputMsg">Message</label>
<textarea class="form-control" rows="8" id="InputMsg" placeholder="Please begin typing your message..." name="emailMessage"></textarea>   
</div>    

<button type="submit" class="btn btn-primary pull-right">Send</button>
</form>


根据我们的评论讨论,您应该能够按照第二页的内容做一些事情。请务必更正我的电子邮件地址,我不确定get_用户是否以这种方式返回电子邮件地址

<?php

$displayname = $_GET['displayname'];

$args1 = array(
 'role' => 'committee',
 'orderby' => 'user_nicename',
 'order' => 'ASC'
);
$committee = get_users($args1);

$matchingEmail = false;
foreach ($committee as $user) {
    if ( !$matchingEmail && $user->display_name == $displayname ) {
        // great, we found our match
        $matchingEmail = $user->email_address; // I don't know if email_address is right, double check this and modify if necessary
    }
}

if ( $matchingEmail ) {
    // only proceed if a matching email address is found
    ?>
    <form role="form" method="post" action="../mailuser.php">  

        <div class="form-group">

            <input type="hidden" name="displayname" value="<?php echo $displayname; ?>">
            <input type="hidden" name="matchingEmail" value="<?php echo $matchingEmail; ?>">
            <input type="text" name="hp" class="hp" value="" alt="if you fill this field out then your email will not be sent">

        </div>


        <div class="form-group">
            <label for="InputName">Your name</label>
            <input type="name" class="form-control" id="InputName" placeholder="Enter your name" name="username">
        </div>

        <div class="form-group">                      
            <label for="InputEmail">Email address</label>
            <input type="email" class="form-control" id="InputEmail" placeholder="you@example.com" name="emailFrom">
        </div>

        <div class="form-group">                             
            <label for="InputMsg">Message</label>
            <textarea class="form-control" rows="8" id="InputMsg" placeholder="Please begin typing your message..." name="emailMessage"></textarea>   
        </div>    

        <button type="submit" class="btn btn-primary pull-right">Send</button>
    </form>
    <?php
} else {
    ?>
    <p>Something is wrong, I can't find your email address! Please try again.</p>
    <?php
}
?>

最后,在第三页,在发送电子邮件的地方,您可以执行以下操作:

<?php $mail->addAddress(stripslashes( $_POST["matchingEmail"] ) ); ?>


您在数据库中有显示名称和电子邮件地址吗?@MikeWillis因此用户名和电子邮件地址存储在数据库中,但使用Wordpress作为我的后端。因此,如果你看一下我脚本的第一部分,它将显示我如何访问和显示它们。好的,我不确定get_用户是如何工作的。在这种情况下,为什么不在第二页上查找电子邮件地址,使用displayname作为匹配项?这就是我遇到的问题,我认为这是最合理的方法,但不确定实现这一点的最佳方法是什么?get_用户是否返回displayname和电子邮件地址?如果是这样,在第二页,你可以做另一个get_users,循环浏览列表,找到一个与displayname匹配的,并提取电子邮件地址。然后$mail->To=$matchedEmailAddress;应该做trickOk,所以在发送邮件之前一切正常。我收到此错误:邮件无法发送。邮件错误:您必须提供至少一个收件人电子邮件地址。我的错误,应该是,请重试。您是否使用PHPMailer?如果so$mail->To不正确,您将使用“必须有其他事情发生”,它应该只向addAddress()添加的地址发送电子邮件。我们如何移动这个来聊天?酷,很高兴我能帮上忙!