插入PHP中的所有字段并通过电子邮件发送
这是我的密码 我正在将表单数据插入数据库。它正在成功地工作,但我还想将表单数据发送到电子邮件ID中,这样我们也可以接收电子邮件ID中的所有数据 请建议我应该做什么;我的代码中需要什么样的更改插入PHP中的所有字段并通过电子邮件发送,php,mysql,database,email,insert,Php,Mysql,Database,Email,Insert,这是我的密码 我正在将表单数据插入数据库。它正在成功地工作,但我还想将表单数据发送到电子邮件ID中,这样我们也可以接收电子邮件ID中的所有数据 请建议我应该做什么;我的代码中需要什么样的更改 <?php $host = "localhost"; $username = "0000000"; $password = "0000000"; $db_name = "0000000"; $con=mysql_connect("$host", "$userna
<?php
$host = "localhost";
$username = "0000000";
$password = "0000000";
$db_name = "0000000";
$con=mysql_connect("$host", "$username", "$password") or die("cannot connect"); // MySQL connection
mysql_select_db("$db_name") or die("can not select DB"); // Select database
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$message = $_POST['message'];
$rdDomestic = $_POST['rdDomestic'];
$fromCity = $_POST['fromCity'];
$toCity = $_POST['toCity'];
$dtDeparture = $_POST['dtDeparture'];
$dtReturn = $_POST['dtReturn'];
$cmbAdult = $_POST['cmbAdult'];
$cmbChild = $_POST['cmbChild'];
$cmbChild = $_POST['cmbChild'];
$cmbInfants = $_POST['cmbInfants'];
$rdClass = $_POST['rdClass'];
$query = "INSERT INTO `insert_flight`(`F_Inq_ID`, `name`, `mobile`, `email`, `message`, `rdDomestic`, `fromCity`, `toCity`, `dtDeparture`, `dtReturn`, `cmbAdult`, `cmbChild`, `cmbInfants`, `rdClass`)
VALUES ('', '$name', '$mobile', '$email', '$message', '$rdDomestic', '$fromCity', '$toCity', '$dtDeparture', '$dtReturn', '$cmbAdult', '$cmbChild', '$cmbInfants', '$rdClass')";
mysql_query($query) or die('Query "' . $query . '" failed: ' . mysql_error());
// Starting email sending data below //
mysql_close($con);
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "New Flight Inquiry Received";
$email_to = "0000000@gmail.com";
$message = "Full Name: $name\n"
. "Mobile: $mobile\n"
. "Email: $email\n"
. "message: $message\n"
. "From City: $fromCity\n"
. "To City: $toCity\n";
mail($email_to, $subject, $message, $header);
// End sending email data...
if ($query) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you!!!! We received your request. We will contact you shortly.');
window.location = 'index.php';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, 0000');
window.location = 'index.php';
</script>
<?php
}
?>
试试这个:
$to = '0000000@gmail.com';
$subject = 'New Flight Inquiry Received';
$msg = '
<html>
<head>
<title>User Details</title>
<body>
<table width="100%" border="0">
<tr><td>Full Name</td><td>' . $name . '</td></tr>
<tr><td>Mobile</td><td>' . $mobile . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>message</td><td>' . $message . '</td></tr>
<tr><td>From City</td><td>' . $fromCity . '</td></tr>
<tr><td>To City</td><td>' . $toCity . '</td></tr>
</body>
</html>';
$from = 'MIME-Version: 1.0' . "\r\n";
$from .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$from .= 'From: info@abcd.com';
mail($to, $subject, $msg, $from);
$to='1!'0000000@gmail.com';
$subject='收到新航班查询';
$msg='1
用户详细信息
全名'$名字。”
“手机”$手机。”
电子邮件'$电子邮件。”
信息'$留言。”
来自城市'$来自城市。”
“去城市”$托西蒂。”
';
$from='MIME版本:1.0'。“\r\n”;
$from.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
$from.='from:info@abcd.com';
邮件($to$subject$msg$from);
此代码集成在您的页面中。检查垃圾邮件文件夹,并使用mysqli
而不是mysql。您的电子邮件可能会成为垃圾邮件。如果可能,您可以在phpMailer的行中使用某种东西,它使用smtp身份验证发送电子邮件,但这不会生成格式良好的HTML;头
和表
都缺少结束标记。