我是否因为这个问题在我的智慧结束时(我想)。我不知道我做错了什么,那里必须存在的一切都有,但这仍然没有用。
我使用过不同的表单和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
感谢高级。
答案 0 :(得分:1)
您正在使用变量名称两次(大写和小写),并且您要发送两次电子邮件。这有点乱。以下是您的代码中的一些问题:
$Body
未定义$Email
未定义(大写)$Message
未定义(大写)这样可以更容易地找到错误。
答案 1 :(得分:0)
$ 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);
答案 2 :(得分:0)
答案 3 :(得分:0)
使用$ message而不是$ Message,因为您在上面定义了小写的'm'。
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;