我的表单有问题,基本上是邮件正在发送,但是没有我的数据。对我来说,看起来不错, 响应显示:
baseURL: "http://localhost:3000/"
data: "{"name":"asda","email":"asdad@wp.ll","message":"asdad"}"
Data
是常规的json,但是在两边都显示了基本URL localhost
可能是问题所在?
我也在本地主机和服务器上尝试过PS,但结果是相同的。
NuxtJS发送方法:
export default {
name: "Contact",
data() {
return {
formMessage: "Form succesfull send",
form: {
name: "asdad",
email: "asdads@gmail.com",
message: "czxczsdqw"
}
};
},
computed: {
formValid() {
return Object.keys(this.fields).every(field => {
return this.fields[field] && this.fields[field].valid;
});
}
},
methods: {
formSubmit(e) {
e.preventDefault();
this.$axios
.post(
"url-to-php-script",
JSON.stringify(this.form))
.then(res => {
console.log(res);
this.formMessage = "Form successfull send";
});
}
}
};
和php邮件文件:
<?php
$name = $_POST['name'];
$from = $_POST['email'];
$message = $_POST['message'];
$message_content = "<h1>Name: $name</h1>";
$message_content .= "<p>From: $from</p>";
$message_content .= "<p>Message: $message</p>";
$to_email = 'kaawkamateusz@gmail.com';
$subject = "Mail from kawkamateusz.pl";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=UTF-8';
$headers[] = 'kawkamateusz.pl';
mail($to_email, $subject, $message_content, implode("\r\n", $headers));
?>
**对不起,如果英语不清楚,我不是母语人
答案 0 :(得分:0)
fetch
与URLSearchParams
一起使用时,一切正常-对于将来的访问者。
fetch(`xxx.php`, {
method: "post",
body: new URLSearchParams(this.form)
})