1
這是我的代碼。在PHP中插入並通過電子郵件發送所有字段
我將表單數據插入到數據庫中。它正在成功運行,但我也希望將表單數據發送到電子郵件ID,因此我們也可以接收電子郵件ID中的所有數據。
請建議我應該做什麼;我的代碼需要什麼樣的更改?
<?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 Inquiery Received";
$email_to = "[email protected]";
$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
}
?>
問題是? –
檢查垃圾郵件文件夾並使用mysqli而不是mysql。 – MajidTaheri
也許你的電子郵件會發送垃圾郵件。如果可能的話,你可以使用phpMailer中的某些東西,它使用smtp認證發送電子郵件 – rakeshjain