dongwei1954 2016-11-29 16:06
浏览 16

根据下拉列表获取发送到不同地址的表单

I have a form that I am trying to get to send to different email addresses based on dropdown choice, and I know no php. I have pieced several form pieces together so I probably have conflicting data. I get it to act like it is working, after I hit submit, it brings me to my PHP page but the page shows blank and the email doesn't end up sending. I have tried to remove the extra unnecessary information, but I am at a loss as to what I am doing wrong.

HTML

<p><form name="htmlform" method="post" action="html_form_send-quote.php">
<table width="100%" border="0" cellspacing="10px" cellpadding="10px">
<tbody>
<tr>
  <td>Nearest Location*</td>
  <td><select id="mailTo" name"mailTo" onchange="changeVal()">
    <option value="loc1">Location 1</option>
    <option value="loc2">Location 2</option>
    <option value="loc3">Location 3</option>
    </select></td>
</tr>
<tr>
  <td>Name*</td>
  <td><input type="text" name="name" size="60" value=""></td>
</tr>
<tr>
  <td>E-Mail*</td>
  <td><input type="text" name="email" size="60" value=""></td>
</tr>
<tr>
  <td>I'm interested in* </td>
  <td><textarea name="comments" cols="60" rows="5"></textarea></td>
</tr>

My PHP

// CHANGE THE TWO LINES BELOW
switch($mailTo) {
    case 'loc1':
        $to = "email1@example.com";
        break;
    case 'loc2':
        $to = "email2@example.com";
        break;
    case 'loc3':
        $to = "email3@example.com";
        break;  
}
$result = mail($name, $email, $phone, $address, $city, $state, $zip, $calltime, $comments);

$email_subject = "Website Quote Request";


function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['phone']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
}

$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'Please enter your name<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'Please describe your requst.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.

";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "Name: ".clean_string($name)."
";
$email_message .= "Email: ".clean_string($email_from)."
";
$email_message .= "Comments: ".clean_string($comments)."
";

// create email headers
$headers = 'From: '.$email_from."
".
'Reply-To: '.$email_from."
" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
<html>...</html>

<?php
}
die();
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么