[英]PHPmailer: allow copy of email to be sent to sender if they check a box
I want users to be able to select a box that says "Send me a copy of the email" after completing a form. 我希望用户在填写表格后能够选择一个框,上面写着“向我发送电子邮件副本”。 I'm using phpMailer to send the form to myself, and I don't know how to add a second email address under the condition that the person selected this box.
我正在使用phpMailer将表单发送给自己,而且在该人选择此框的情况下,我不知道如何添加第二个电子邮件地址。 Right now I have:
现在我有:
if (isset($_POST["send"])) {
$senderEmail = $email;
}
and 和
<li>
<h4>Send me a copy of this form</h4>
<input type="radio" id="send" name="send">
<label for="send">Yes please</label>
<input type="radio" id="nosend" name="nosend">
<label for="nosend">No, thank you</label>
</li>
and finally 最后
include("includes/class.phpmailer.php");
$mail = new PHPMailer;
$mail->setFrom($email, $firstname);
$mail->addAddress('email@address.com');
$mail->addAddress($senderEmail);
$mail->addReplyTo($email, $name);
$mail->isHTML(true);
$mail->Subject = 'New email from ' . $name;
$mail->Body = "
<h2>Email from your Website</h2>
<p>Name: $firstname $lastname </p>
<p>Email: $email </p>
<p>Phone: $phone </p>
<p>Country: $
<p>Message: $comments </p>
";
Also, while we're looking at it, in the Body of the email as listed above, I want to get the information for Country which is in a dropdown selection menu. 另外,在查看的同时,在上面列出的电子邮件正文中,我想在下拉选择菜单中获取“国家/地区”的信息。 If anyone can also tell me how to do this, as well as how to do the same from whichever selection a sender makes from a radio checklist, I'd be very grateful.
如果有人还可以告诉我该如何做,以及如何从发送者从无线电清单中进行的任何选择中做到这一点,我将不胜感激。
You're sending two parameters nosend
and send
when you only need one: send
. 您所发送的两个参数
nosend
和send
时,你只需要一个: send
。 That one will be either true
or false
depending on which radio is selected. 根据选择的无线电,该信号将为
true
或为false
。 Note that both their names are send
now and I added value
attributes. 请注意,它们的名称都立即
send
并且我添加了value
属性。
<input type="radio" id="send" name="send" value="true">
<input type="radio" id="nosend" name="send" value="false">
Since there are only two options, it might make more sense to use a checkbox instead of radios. 由于只有两个选项,因此使用复选框而不是单选可能更有意义。 Radio inputs are more appropriate when there are more than two options.
当选项多于两个时,无线电输入更为合适。
<input type="checkbox" id="send" name="send" value="true">
Then, in you're mailing logic, only add the additional address if the send
parameter is set to the appropriate value. 然后,在您的邮件逻辑中,仅当
send
参数设置为适当的值时,才添加其他地址。
$mail->addAddress('email@address.com');
if (isset($_POST['send']) && $_POST['send'] == 'true') {
$mail->addAddress($senderEmail);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.