【发布时间】:2011-08-09 14:16:58
【问题描述】:
<?php
$con = mysql_connect("localhost", "root");
if (!$con)
{
die("Cannot make a connection");
}
$customer_first_name = $_POST['customer_first_name'];
$customer_last_name = $_POST['customer_last_name'];
$customer_email = $_POST['customer_email'];
$category_id = $_POST['category_id'];
$problem_body = $_POST['problem_body'];
mysql_select_db('yumbox_table', $con) or die(mysql_error());
mysql_query("INSERT INTO yumbox_customer_inquiry (customer_last_name, customer_first_name, customer_email, category_id, problem_body) values ($customer_last_name, $customer_first_name, $customer_email, $category_id, $problem_body)", $con);
if ($category_id==1)
{
mail('technical_problems_11@yahoo.com… 'You have a new email from $customer_first_name $customer_last_name at $customer_email', $problem_body);
}
if ($category_id==2)
{
mail('login_problems11@yahoo.com', 'You have a new email from $firstname $lastname at $emailaddress', $problem_body);
}
if ($category_id==3)
{
mail('order_problems_11@yahoo.com', 'You have a new email from $firstname $lastname at $emailaddress', $problem_body);
}
echo('Thank you for sending us your feedback. A customer support representative will respond to you shortly');
mysql_close($con)
?>
在一个 html 页面中,假设用户在表单中输入信息,并且假设数据进入这个 php 文件。假设从这里将其存入 mysql 表,并且该数据也假设发送到电子邮件地址。但是,它不会将代码发送到 mysql 表,并且您会收到一条错误消息,指出它不能通过电子邮件发送。有人可以帮我解决这个莫名其妙的问题吗?
【问题讨论】:
-
代码中的一些缩进会大有帮助。您应该使用 mysql_real_escape_string($query) 来阻止注入攻击,因为您使用的是来自 $_POST 的不受信任的输入
标签: php mysql html database email