PHP表单,html <select>将表单发送到不同电子邮件的Box未执行


My PHP form with an html <select> box that sends form to different emails isn't executing

我仍然是新的php,所以我敢肯定这是一个愚蠢的错误在这里的某个地方,但我不能弄清楚为什么我的表单没有被发送到任何电子邮件我已经分配在用户框。我以为这只是一个简单的"if"语句,但当我在表单上点击提交时,据我所知,它无处可去。它甚至不会执行。看一下我的代码,看看是否有语法问题或其他问题:

<?php
$hostname  =  "db.example.com";
$database  =  "poweri3_blank";
$username   =  "script";
$password   =  "xxxxxx";
$conn  =   mysql_connect($hostname, $username, $password) or DIE("Unable to connect to database"); 
$dbconnection  =  $conn;
mysql_select_db($database) OR DIE("Unable to select database");
/* Subject and Email Variables- */
$emailSubject = 'Request for Provider'; 
$webMaster = 'me@gmail.com'; 
/*Gathering Data Variables*/
$firstName  =  $_POST['firstName'];
$lastName  =  $_POST['lastName'];
$email  =  $_POST['email'];
$zipCode = $_POST['zipCode'];
$provider = $_POST['provider'];
$comment = $_POST['comment'];
//send e-mail to different providers
if($provider=="p1") $sendTo = "p1@gmail.com";
if($provider=="p2") $sendTo = "p2@gmail.com";
if($provider=="p3") $sendTo = "p3@gmail.com";
if($provider=="p4") $sendTo = "p4@gmail.com";
$body = <<<EOD
<br><hr><br>//--------CONTACT--------//<br><br>
Name: $firstName $lastName<br><br>
Email: $email<br><br>
Cable or Satellite Provider: $provider<br><br>
Zip/Postal Code: $zipCode<br><br>
Your Message: $comment<br><br>
EOD;
$headers = "From: $email'r'n";
$headers .= "Content-type: text/html'r'n";
$success = mail($webMaster,$emailSubject,$body,$headers);
//Enter Data Into Table
$sql = "INSERT INTO poweri3_blank.provider_contact (
            firstName,
            lastName,
                        email,
                        zip_code, 
                        provider, 
                        comment                       
            )
        VALUES(
            '".$firstName."',
            '".$lastName."',
                        '".$email."',
                        '".$zipCode."',
                        '".$provider."',
                        '".$comment."')";
$result  =  mysql_query($sql) or die("Couldn't execute query: $sql");
//$result  =  mysql_query($sql) or die(mysql_error());
// Kill connection
mysql_close($conn);
/*Results rendered as HTML

$theResults = <<<EOD
<html>
<head>
<title>Yourpage title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>
<div>
<div align="left">Thank You For Your Interest. </div>
</div>
</body>
</html>
EOD;

echo "$theResults";*/
?>

我在MODx工作,如果有人想知道。谢谢。对不起,我通常不会问,但我完全迷路了。如果页面出现错误,这是一回事,但它只是没有做任何事情(据我所知)。

我不知道你的意思是什么

//send e-mail to different providers
if($provider=="p1") $sendTo = "p1@gmail.com";
if($provider=="p2") $sendTo = "p2@gmail.com";
if($provider=="p3") $sendTo = "p3@gmail.com";
if($provider=="p4") $sendTo = "p4@gmail.com";

是由于您在脚本后面似乎根本没有使用$sendTo。

如果您想知道它是否正在做任何事情,请使用一些echo语句,包括关于$success变量的语句。if(!$success) echo "error";之类的

同时,当前抛出了哪些错误?

你是说$success = mail($sendTo,$emailSubject,$body,$headers); ?

$success = mail($webMaster,$emailSubject,$body,$headers);
应该

$success = mail($sendTo,$emailSubject,$body,$headers);

如果你正在使用邮件功能,你需要在你的服务器上设置SMTP。

如果你不知道如何设置,可以尝试使用PHPMailer。