【发布时间】:2016-06-08 21:19:56
【问题描述】:
这实际上是我在这里的第一篇文章。可能是分号问题,但我会试一试,因为我的头疼比埃菲尔铁塔还大。
所以我在我的网站上添加了一个联系表单,但它存在问题,因为它正在发送电子邮件但当我收到它时它是空的。它仅显示 PHP 文件中的文本(名称:、电子邮件:等),但不显示输入表单中的内容。
代码如下所示: HTML
<div class="contact-form bottom">
<h2>Send a message</h2>
<form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="form-group">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" required="required" placeholder="Email Id">
</div>
<div class="form-group">
<textarea name="message" required class="form-control" rows="8" placeholder="Your text here"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-submit" value="Submit">
</div>
</form>
</div>
和PHP:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$message = @trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'a.truta@icloud.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Message: ' . $message;
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
请帮忙,我在这里要疯了!
【问题讨论】:
-
你只是假设成功。您从不费心实际检查
mail()返回值,因此即使它爆炸并吐得满地都是,您仍然会发出“成功”。你有没有做过任何基本的调试,比如var_dump($_POST)看看 PHP 收到了什么? -
在调试脚本时不要使用
@。您想查看所有警告,因为它们可能表明存在问题。 -
我知道你在说什么,我不想听起来很愚蠢,但我是这个领域的新手,我的首要任务是前端。这就是为什么我在使用简单的联系表格时遇到问题的原因..