我的 PHP 表单带有 html
我对 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 = '[email protected]';
/*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 = "[email protected]";
if($provider=="p2") $sendTo = "[email protected]";
if($provider=="p3") $sendTo = "[email protected]";
if($provider=="p4") $sendTo = "[email protected]";
$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 中工作。谢谢。抱歉,我通常不会问,但我完全迷失了。如果页面出错,那是一回事,但它只是没有做任何事情(据我所知)。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定你的意义
是什么,因为你似乎在脚本的后面根本没有使用 $sendTo 。
如果您想知道它是否正在执行任何操作,请使用一些
echo
语句,其中包括$success
变量上的语句。if(!$success) echo "error";
或者其他什么。另外,目前抛出了什么错误?
I'm not sure what the point of your
is since you don't seem to use the $sendTo at all later in the script.
If you want to know if it is doing anything use some
echo
statements, including one on the$success
variable.if(!$success) echo "error";
or something.Also, what errors are being thrown at the moment?
你的意思
$success = mail($sendTo,$emailSubject,$body,$headers);
?Did you mean
$success = mail($sendTo,$emailSubject,$body,$headers);
?如果
您使用邮件功能,则需要在您的服务器中设置 SMTP。
如果您不知道如何设置,请尝试使用 PHPMailer。
should be
If you are using mail function, you need to setup SMTP in your server.
If you don't know how to setup , try with PHPMailer.