我正在寻求更多关于处理此问题的建议。
我有一个页面,其中包含指向每个管理员的链接,点击后会显示其名称。在第二页上,它是一个表单,显示名称并使用其显示名称填充主题字段。我需要获取与该用户关联的电子邮件地址,但将其用作第二页上的表单发送到的电子邮件地址,因为目前我的脚本只能将其发送到我硬编码的电子邮件地址。
所以第一页是:
<?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>
我的发送脚本将我的电子邮件硬编码为:
$ mail-&gt; From ='myemail@dummy.com';
所以我需要根据您首先点击的人而变化。它需要发送到我的硬编码电子邮件以及Wordpress用户数据库中与之关联的人员电子邮件。
答案 0 :(得分:1)
根据我们的评论讨论,您应该可以在第二页上执行以下操作。请务必更正我的email_address,我不确定get_users是否返回电子邮件地址。
<?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
}
?>
最后在第3页,您发送电子邮件的地方,您可以执行以下操作:
<?php $mail->addAddress(stripslashes( $_POST["matchingEmail"] ) ); ?>