PHP post 数据未通过
PHP post data isn't being sent through
呃,我对这个问题束手无策(我想)。我看不出我做错了什么,所有必须存在的东西都在那里,但这仍然不起作用。
我使用了不同的表单和 PHP 邮件脚本,但似乎没有任何效果。正在发送电子邮件,但信息始终为空白。 示例见截图。
我做错了什么?
请帮忙。
表单代码如下:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row-fluid">
<div class="span5">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
</div>
<div class="span7">
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
</div>
</div>
</form>
这里是 整个 PHP 文件 (sendemail.php):
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = @trim(stripslashes($_POST['first_name']));
$lastname = @trim(stripslashes($_POST['last_name']));
$email = @trim(stripslashes($_POST['email']));
$message = @trim(stripslashes($_POST['message']));
$email_from = "Website Contact Form";
$email_to = '//removed real email address';
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = mail($EmailTo, $Subject, $Body, "From: <$email_from>");
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
您在此处看到的具有当前代码的表单网页 运行 是:http://minha-consulting.com/contactus.html
高级感谢。
$Body 的第一行不应以“.”开头。
$Body = "Name: ";
如果您用小写字母定义变量,则不能用大写字母调用它。
$test != $Test
只需复制并替换您的代码:
$name = @trim(stripslashes($_POST['first_name']));
$lastname = @trim(stripslashes($_POST['last_name']));
$email = @trim(stripslashes($_POST['email']));
$message = @trim(stripslashes($_POST['message']));
$subject = 'Email Subject';
$headMail = "From: your@email.address\r\n";
$headMail .= "From: your@email.address\r\n";
$bodyMail = "Name: ";
$bodyMail .= $name . ' ' . $lastname;
$bodyMail .= "\n";
$bodyMail .= "Email: ";
$bodyMail .= $email;
$bodyMail .= "\n";
$bodyMail .= "Message: ";
$bodyMail .= $message;
mail($email, $subject, $bodyMail, $headMail);
The variable name is case-sensitive.
http://php.net/manual/en/language.variables.basics.php
$Message
和 $message
不一样。同样修复其他变量。
您使用了两次变量名(大写和小写)并且发送了两次电子邮件。这有点乱。以下是您的代码中的一些问题:
$Body
未定义
$Email
未定义(大写)
$Message
未定义(大写)
- 为什么要使用 stripslashes?最好使用 Sanitize filters.
- 使用适当的缩进清理代码并使用 PHP 编码标准
这样bug会更容易找到。
使用 $message 而不是上面定义的小写字母 'm' 中的 $Message。
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
呃,我对这个问题束手无策(我想)。我看不出我做错了什么,所有必须存在的东西都在那里,但这仍然不起作用。
我使用了不同的表单和 PHP 邮件脚本,但似乎没有任何效果。正在发送电子邮件,但信息始终为空白。 示例见截图。
我做错了什么?
请帮忙。
表单代码如下:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row-fluid">
<div class="span5">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
</div>
<div class="span7">
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
</div>
</div>
</form>
这里是 整个 PHP 文件 (sendemail.php):
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = @trim(stripslashes($_POST['first_name']));
$lastname = @trim(stripslashes($_POST['last_name']));
$email = @trim(stripslashes($_POST['email']));
$message = @trim(stripslashes($_POST['message']));
$email_from = "Website Contact Form";
$email_to = '//removed real email address';
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = mail($EmailTo, $Subject, $Body, "From: <$email_from>");
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
您在此处看到的具有当前代码的表单网页 运行 是:http://minha-consulting.com/contactus.html
高级感谢。
$Body 的第一行不应以“.”开头。
$Body = "Name: ";
如果您用小写字母定义变量,则不能用大写字母调用它。
$test != $Test
只需复制并替换您的代码:
$name = @trim(stripslashes($_POST['first_name']));
$lastname = @trim(stripslashes($_POST['last_name']));
$email = @trim(stripslashes($_POST['email']));
$message = @trim(stripslashes($_POST['message']));
$subject = 'Email Subject';
$headMail = "From: your@email.address\r\n";
$headMail .= "From: your@email.address\r\n";
$bodyMail = "Name: ";
$bodyMail .= $name . ' ' . $lastname;
$bodyMail .= "\n";
$bodyMail .= "Email: ";
$bodyMail .= $email;
$bodyMail .= "\n";
$bodyMail .= "Message: ";
$bodyMail .= $message;
mail($email, $subject, $bodyMail, $headMail);
The variable name is case-sensitive.
http://php.net/manual/en/language.variables.basics.php
$Message
和 $message
不一样。同样修复其他变量。
您使用了两次变量名(大写和小写)并且发送了两次电子邮件。这有点乱。以下是您的代码中的一些问题:
$Body
未定义$Email
未定义(大写)$Message
未定义(大写)- 为什么要使用 stripslashes?最好使用 Sanitize filters.
- 使用适当的缩进清理代码并使用 PHP 编码标准
这样bug会更容易找到。
使用 $message 而不是上面定义的小写字母 'm' 中的 $Message。
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;