我正在尝试这个sendemail.php脚本。它正在发送邮件,但它不会发送在表单的文本框中输入的数据。
sendemail.php
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent! We Will get back to you soon. :)'
);
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
// $name = $_POST['name'];
// $email = $_POST['email'];
// $subject = $_POST['subject'];
// $message = $_POST['message'];
$email_from = $email;
$email_to = 'dhaval@geekslabstudios.com' . ' , ' ;
$email_to .='kamal@geekslabstudios.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
index.html表单
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-5">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" required="required" placeholder="First Name">
</div>
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Last Name">
</div>
<div class="form-group">
<input type="text" name="email" id="email" class="form-control" required="required" placeholder="Email address">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg">Send Message</button>
</div>
</div>
<div class="col-sm-7">
<textarea id="message" name="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
</div>
</form>
它发送邮件但我收到的是这样的:
名称:
电子邮件:
主题:
消息:
答案 0 :(得分:0)
你的代码中的每件事都很好看。
如果您在收件箱中收到邮件,则表示您的邮件功能正常运行。您应该检查$_POST
中获得的值。如果您使用AJAX
发送请求,请检查您的JavaScript代码。或者发布在这里以便更好地理解问题。