我想将此表单的数据作为电子邮件发送到不同的邮件 根据不同的城市地址;例如:人的细节 选择“gampaha”到email1@mail.com并选择人员的详细信息 科伦坡到email2@mail.com等...请帮助我。
<form action="">
<ul>
<li><input name="name" type="text" placeholder="type name" /></li>
<li><input name="email" type="email" placeholder="type email"/></li>
<li><input name="num" type="number" placeholder="type contact number" /></li>
<select name="city">
<option value="gampaha">gampaha</option>
<option value="colombo">colombo</option>
<option value="ragama">ragama</option>
<option value="jaffna">jaffna</option>
</select>
<li><input name="submit" type="submit" /></li>
</ul>
</form>
答案 0 :(得分:1)
假设$to
是收件人电子邮件地址:
if(isset($_POST['submit'])) {
switch($_POST['city']) {
case 'gampaha': $to = 'to1@gmail.com'; break;
case 'colombo': $to = 'to2@hotmail.com'; break;
}
}
下次,请显示您已尝试过的代码。而不是依赖别人为你做的工作,自己尝试一下。如果它不起作用,请再试一次。如果这不起作用,请发布您的代码并询问它出错的地方。
答案 1 :(得分:0)
这是我的想法:
#assuming you are POSTing
# use a DB or have some static references to the options.
$choices["gampaha"] = "mail1@mail.net";
$choices["colombo"] = "mail2@mail.net";
if (isset($_POST["submit"])){
$to = $choices[$_POST["city"]];
$r = mail($to, "email request", $_POST['name']." ".$_POST["email"]." ".$_POST["num"]);
}
http://php.net/manual/en/function.mail.php
答案 2 :(得分:0)
只想再向您展示logic
:
<?php
$arr_city_email = array(
"gampaha" => "email1@gmail.com",
"colombo" => "email2@gmail.com"
);
if(isset($_POST['submit'])) {
$city = $_POST['city'];
$to = $arr_city_email[$city];
}
?>