我想将数据以及邮件中的某些地址发送到数据库,但数据库没有注册。
<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, 'cc');
if (!$select_db){
die("Database Selection Failed" . mysqli_error($connection));
}
?>
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<?php
require_once('connect.php');
require_once('config.php');
require('PHPMailer/PHPMailerAutoload.php');
if(isset($_POST) & !empty($_POST)){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if(!isset($name) || empty($name)){
$error[] = "Name is required";
}
if(!isset($email) || empty($email)){
$error[] = "E-Mail is required";
}
if(!isset($subject) || empty($subject)){
$error[] = "Subject is required";
}
if(!isset($message) || empty($message)){
$error[] = "Message is required";
}
if(!isset($error) || empty($error)){
$to = "vivek@codingcyber.com";
$headers = "From : " . $email;
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPSecure = 'tls';
$mail->Host = $smtphost;
$mail->SMTPAuth = true;
$mail->Username = $smtpuser;
$mail->Password = $smtppass;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->CharSet = 'UTF-8';
$mail->setFrom('', 'PixelW3 Technologies');
$mail->addAddress('', '');
$mail->Subject = $subject;
$mail->Body = $message . " Name : " . $name . ". E-Mail : " . $email;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
$sql = "INSERT INTO `contact` (name, email, subject, message) VALUES ('$name', '$email', '$subject', '$message')";
if(mysqli_query($connection, $sql)){
echo 'Message has been sent, we will get back to you soon';
}
}
慕田峪4524236