你好只需要在gmail上發送消息。表單提交應該使用 jQuery 來實現。我想我不能將數據從 jquery 傳遞到 php。沒有 jquery 文件的消息正在 gmail 上發送,但是當我在 html 上包含 jquery 時,它說消息已成功發送,但 gmail 上沒有任何顯示這是主要的 PHP 文件<?phprequire '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 文件<?phperror_reporting(0);$firstname = $_POST['firstname'];$lastname = $_POST['lastname'];$email = $_POST['email'];$sub = $_POST['subject'];$message = $_POST['message'];if (isset($_POST['submit'])){ $to = '[email protected]'; $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.";
2 回答

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊
正如@BlackXero 所提到的,您正在進行以下檢查:
if (isset($_POST['submit']))
這通常在您直接從 html 或 php 向 Sendmail.php 提交表單時使用。所以在這種情況下你不需要那個檢查。
同樣在此示例中,由于您為表單添加了方法和操作屬性,您的表單仍在嘗試提交某處。在這種情況下,您可以(可能應該)刪除它們并將e.preventDefault()
加到按鈕單擊功能的開頭。
- 2 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消