php - 基于使用 PHPMailer 选择的单选按钮的不同自动响应反馈
问题描述
我正在使用 PHPMailer 收集表单数据并发送和自动回复用户邮件。我有 3 个不同的单选按钮可供选择。我需要根据选定的单选按钮自定义自动响应。
<form action="mailer.php" method="POST" name="xform">
<input type="radio" name="summit" id="summit" value="bird" >
<label for="summit">regular</label>
<input type="radio" name="summit" id="summit1" value="duck">
<label for="summit1">vip</label>
<input type="radio" name="summit" id="summit2" value="eagle">
<label for="summit2">vvip</label>
<button name="submitted" type="submit" >Send</button>
</form>
For PHPMAILER
if(isset($_POST['submitted'])){
$which = $_POST['summit'];
<!--this picks the selected radio button value -->
}
<!--For Autoresponse -->
if($mail->send()){
$autoemail->Body = "I need a way to customize this body of the auto respose mail in accordance with the selected radio button, like if $which is an array, how do I customize the auto response in accordance with the selected child";
}
请注意,我的 PHPMAILER 配置工作正常,没有问题。
解决方案
嗯,你需要在发送消息之前设置body !
根据您的单选按钮值选择不同的消息正文:
switch($_POST['summit']) {
case 'bird':
$mail->Body = "Message body 1";
break;
case 'duck':
$mail->Body = "Message body 2";
break;
case 'eagle':
$mail->Body = "Message body 3";
break;
}
$mail->send();
您当然可以从任何来源获取您的消息内容 - 从外部文件、数据库、外部 HTTP 请求等 - PHPMailer 不在乎它来自哪里,只要您将其放入Body
.
推荐阅读
- c# - 高速处理列表的多个计时器导致问题
- django - 在给定主键的情况下添加到多对多关系
- terminal - 在终端上管道重复输出
- sql - 同时选择 Distinct 和 sequence
- python - 地图功能花费太多时间(Pandas DataFrame)
- mysql - Laravel - 带有子查询的查询构建器
- c# - 如何在 C# 类对象中序列化这种类型的 json 字符串?
- r - 带有误差线的线图,其中每条线是一个不同的组,多个变量位于 x 轴上
- c# - 使用 Dapper、Azure SQL 和 .NET Core 3.1 的 Azure Web 应用程序的性能问题
- javascript - 如何从具有多个页面的单个 URL 的网站的特定页面中抓取信息?