Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未通过php电子邮件接收联系信息_Javascript_Php_Html_Email - Fatal编程技术网

Javascript 未通过php电子邮件接收联系信息

Javascript 未通过php电子邮件接收联系信息,javascript,php,html,email,Javascript,Php,Html,Email,我正在尝试为我的网站制作一个功能性的联系表单。然而,当我将测试电子邮件发送到我的电子邮件地址时,非表单信息将通过电子邮件发送。我收到的电子邮件是“姓名:电子邮件:信息:”。没有信息被发送出去,我也不知道丢失的链接是什么 以下是我的PHP: <?php ini_set("mail.log", "/tmp/mail.log"); ini_set("mail.add_x_header", TRUE); //variables $name = strip_tags(htmlspecialchar

我正在尝试为我的网站制作一个功能性的联系表单。然而,当我将测试电子邮件发送到我的电子邮件地址时,非表单信息将通过电子邮件发送。我收到的电子邮件是“姓名:电子邮件:信息:”。没有信息被发送出去,我也不知道丢失的链接是什么

以下是我的PHP:

<?php
ini_set("mail.log", "/tmp/mail.log");
ini_set("mail.add_x_header", TRUE);

//variables
$name = strip_tags(htmlspecialchars($_POST['Name']));
$email_address = strip_tags(htmlspecialchars($_POST['Email']));
$message = strip_tags(htmlspecialchars($_POST['Message']));

// Create the email and send the message
$to = 'macero143@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from example... contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";

if(mail($to,$email_subject,$email_body,$headers)){ echo "Mail sent!";} else{ echo "Error, check your logs."; }
return true;

通常,在ajax调用的数据{}中发送的值应该被引用,因为它们是JSON对象的一部分。我认为数据对象假设其中有文本值,并且没有从表单字段添加jQuery值,因为它不知道名称应该是该值的键。例如,我会尝试将其更改为:

$.ajax({
    type: 'POST',
    url: "sendemail.php",
    data: {
        "Name": $("#name").val(), // change this line to have quotes around the key
        "Email": $("#email").val(), // change this line to have quotes around the key
        "Message": $("#message").val() // change this line to have quotes around the key

    }
 // the rest of the code here like you have it.

如果这不是问题所在,我也会在发送之前尝试console.log($(“#name”).val())每个值,确保它们包含您期望的值,然后您就会知道这也不是问题所在。

不幸的是,这没有起到作用。当我在控制台中运行它时,它会正确地打印信息。你认为这可能是戈达迪那边的事吗?谢谢,我认为它忽略了脚本中的变量,因为它不知道它们是什么。我会像这样使用字符串插值,看看这是否解决了它$email\u body=“您已收到来自示例…联系人表单的新邮件。\n\n”。“以下是详细信息:\n\n名称:”.$name.\n\n邮件:“.$email\u地址”。\n\n邮件:\n.$message;要么这样,要么就必须在变量周围加上{$name}。更多信息请点击此处: