你好只需要在gmail上发送消息。表单提交应该使用 jQuery 来实现。
我想我不能将数据从 jquery 传递到 php。
没有 jquery 文件的消息正在 gmail 上发送,但是当我在 html 上包含 jquery 时,它说消息已成功发送,但 gmail 上没有任何显示
这是主要的 PHP 文件
<?php
require 'Sendmail.php';
?>
<!doctype html>
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<section>
<h1>Contact Form</h1>
<form action="" method="POST">
<label>Firstname</label>
<input type="text" name="firstname" id="firstname">
<label>Lastname</label>
<input type="text" name="lastname" id="lastname">
<label>Email</label>
<input type="text" name="email" id="email">
<label>Subject</label>
<input type="text" name="subject" id="subject">
<label>message</label>
<textarea name="message" id="message"></textarea>
<a href="index.php">Sign Up</a>
<button type="submit" id="button" name="submit" value="Send message">Send message</button>
</form>
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
<script type="text/javascript" src="ContactValidation.js"></script>
</body>
</html>
这是在 gmail 上发送消息的 PHP 文件
<?php
error_reporting(0);
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$sub = $_POST['subject'];
$message = $_POST['message'];
if (isset($_POST['submit'])){
$to = 'g_chkuaseli@cu.edu.ge';
$subject = "Subject: " . $sub ;
$subject2 = "Copy of your subject: " . $sub;
$message = $firstname . $lastname . " wrote the following message: \n\n" . $message;
$message2 = "Copy of the message: " . $message;
$headers = "From: " .$email;
$headers2= "From: " . $to;
mail($to,$subject,$message,$headers);
mail($email,$subject2,$message2,$headers2);
}
echo "Email sent! Thank you " . $firstname . ", We will contact you shortly.";
翻翻过去那场雪
潇湘沐