我无法在函数mail()之前在数据库中添加查询。
所以我做了一个php表单联系人留言
1.在mysql数据库中插入消息 - 不起作用(它不会在contactmesaj
列中插入查询 - 并且没有向我显示任何错误...)
2.将带有用户信息的邮件发送到我的地址 - 工作
我无法弄清楚我的代码有什么问题......
<?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");
}
}
?>