我正在尝试这个sendemail.php脚本。它正在发送邮件,但没有发送在表单文本框中输入的数据。
发送电子邮件。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>
它发送邮件,但我收到这样:
姓名:
电邮:
主题:
信息:
代码中的每件事情看起来都很好。
如果你在收件箱中收到邮件,这意味着你的邮件功能工作正常。您应该检查在$\u POST
中获得的值。如果您使用AJAX
发送请求,请检查您的JavaScript代码。或者在这里发布,以便更好地理解问题。