【发布时间】:2015-07-15 10:48:04
【问题描述】:
我在接收邮件时遇到问题。我尝试了不同的邮件提供商(微软、雅虎、gmail),但仍然没有收到邮件。我正在为我的朋友开发网站,我购买了一个带有 php 联系人的引导模板。
我正在使用 xampp,我尝试过以这种方式发送邮件,但我已将其上传到其他朋友网站的子文件夹中,但仍未收到。
代码如下: HTML index.php
<form class="js-contact-form" role="form" action="mail/contact.php" method="post" data-parsley-validate>
<div id="msgInfo"></div>
<input type="text" class="form-control wow fadeInLeft name" data-wow-delay="0.2s" placeholder="Name" required data-parsley-error-message="Enter name">
<input type="email" class="form-control wow fadeInLeft email" data-wow-delay="0.4s" placeholder="Email" required data-parsley-error-message="Enter email">
<textarea class="form-control wow fadeInLeft message" data-wow-delay="0.6s" rows="6" placeholder="Message" required data-parsley-error-message="Enter message"></textarea>
<button type="submit" class="btn btn-lg wow fadeInUp" data-wow-delay="1s">Send message</button>
</form>
这里是contact.php代码:
<?php
// PHP script for sending email
//
// Configuration
//
$toEmail = ""; // replace with your email where you would like to send email
$subject = 'Contact form from my website'; // replace with subject you want to receive
$body = 'You have received email from website:'; // replace with text that you want to receive in email
$from = ''; // replace with email that will look like sender
//
// ----- do not edit after this line if you don't understand what you are doing -----
//
if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "Invalid input";
return false;
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body .= "\n";
$body .= "Name: $name\n";
$body .= "Email: $email\n";
$body .= "Message: $message\n";
$headers = "From: $email\n";
$headers .= "Reply-To: $toEmail";
$res = mail($toEmail, $subject, $body, $headers);
echo "OK";
return true;
?>
这不是我第一次使用 php,过去我有一个工作 php(2-3 年前),我也测试过它,但它不起作用 -.-
谁能帮帮我。
【问题讨论】:
-
你可以尝试
var_dump($_POST);吗?你是否尝试用静态值替换所有$_POST(例如$_POST['name']等)?
标签: php forms post html-email