Php 无法在联系人表单中使用mysqli stmt before mail()插入查询
我无法在函数mail()之前在数据库中添加查询。 因此,我制作了一个php表单联系消息 1.在mysql数据库中插入消息-不起作用(它不会在列Php 无法在联系人表单中使用mysqli stmt before mail()插入查询,php,email,mysqli,sql-insert,Php,Email,Mysqli,Sql Insert,我无法在函数mail()之前在数据库中添加查询。 因此,我制作了一个php表单联系消息 1.在mysql数据库中插入消息-不起作用(它不会在列contactmesaj-中插入查询,也不会显示任何错误…) 2.向我的地址发送包含用户信息的邮件-works 我不知道我的代码出了什么问题 <?php session_start(); ?> <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display
contactmesaj
-中插入查询,也不会显示任何错误…)
2.向我的地址发送包含用户信息的邮件-works
我不知道我的代码出了什么问题
<?php session_start(); ?>
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
if(isset($_POST['mesajContact'])){
$name = $_POST['name'];
$email = $_POST['email'];
$mesaj = $_POST['message'];
$telefon = $_POST['telefon'];
$oferta = $_POST['oferta'];
$subiect ='pachet: '.$oferta;
require "connectare_db.php";//open DB
$stmt = $con->prepare("INSERT INTO contactmesaj (nume, mail, mesaj, telefon, oferta) VALUES (?,?,?,?,?)");
$stmt->bind_param("sssss", $nume, $email, $mesaj, $telefon, $oferta);
if($stmt->execute()){
$_SESSION["contactMesaj"]="Succes";//pentru mesaj succes adaugare
} else{
$_SESSION["contactMesaj"]="Failed";
}
$stmt->free_result();
$stmt->close();
$con->close();
$to = 'contact@realizare-site-ieftin.ro, stefan.jucatoru@gmail.com';
$message = 'NUME: '.$name.'<BR> MAIL: '.$email.'<BR>TELEFON: '.$telefon.'<BR>Continut MESAJ: '.$mesaj;
$headers = 'From: '.$email.'' . "\r\n";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $oferta, $message, $headers); //This method sends the mail.
}
//echo '<meta http-equiv="refresh" content="5;URL=../contact.php">';
else{
echo "Invalid Email, please provide an correct email.";
//header("location: ../contact.php");
}
}
?>
一些合理的代码缩进将是一个好主意。它帮助我们阅读代码,更重要的是,它将帮助您为自己的利益调试代码。您可能会被要求在几周/几个月内修改此代码,最终您将感谢我。添加mysqli_报告(mysqli_报告错误| mysqli_报告严格)代码>到您的错误显示设置,以及获取mysqli错误向您喊叫谢谢,我使用上面的代码发现了错误