当前,我正在处理表单,但遇到了问题。
我想不使用表单(仅在div中输入)来发送电子邮件:
<div class="popup-user modal-chat">
<div class="arrow-up"></div>
<div class="test-chat">
<div class="chat-option" contenteditable="false"><input required type="email" name="email" class="yourMail" placeholder="Mail"></div>
<div class="row new-msg">
<div class="input-field col s9">
<input id="sendContent" type="text" class="validate" pattern=".{30,}" required name="message">
<label class="active" for="sendContent">Message here</label>
</div>
<div class="col s3 button-send">
<a class="btn-floating btn-small waves-effect waves-light red unvailable send">
<i class="material-icons">send</i>
</a>
</div>
</div>
</div>
</div>
我想使用Ajax将数据从#sendContent和.yourMail粘贴到PHP文件中,但是我尝试执行的操作不起作用...
这是我的Ajax,但是如何向我的php发送多个数据?:
var email = $(".yourMail").val();
var message = $("#sendContent").val();
console.log(message)
$.ajax({
type : "POST",
url: "assets/php/post.php",
data: {
email : $(".yourMail").serialize(),
message : $("#sendContent").serialize()
},
success : function() {
console.log("success");
},
error: function() {
console.log("not success");
}
});
在PHP中,我只想先发送包含消息内容的邮件,所以基本上它应该看起来像这样?
<?php
header('Content-Type: text/html; charset=utf-8');
$message=$_POST["message"];
$email=$_POST["email"];`enter code here`
mail("myemail@mail.com","My subject",$message);
?>
感谢帮助!
答案 0 :(得分:0)
只需将数据更改为键/值:
data:{'email': email, 'message':message}