亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將數據從 jquery 傳遞到 php,以在 gmail 上發送消息

如何將數據從 jquery 傳遞到 php,以在 gmail 上發送消息

PHP
函數式編程 2021-10-22 10:17:24
你好只需要在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()加到按鈕單擊功能的開頭。


查看完整回答
反對 回復 2021-10-22
?
瀟湘沐

TA貢獻1816條經驗 獲得超6個贊

您不需要包含這個 require 'Sendmail.php',因為表單是使用 ajax 提交的。并在 if 條件下寫下您的消息,即“電子郵件發送”


查看完整回答
反對 回復 2021-10-22
  • 2 回答
  • 0 關注
  • 152 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號