HTML 表单不会发送电子邮件
HTML form won't send email
我的网页上有一个联系我们表格,我正在使用 php 和 jquery 从联系我们表格发送数据。
当我填写数据时,我收到警报 "message sent",但我的电子邮件没有收到任何消息。
这是我的HTML代码
<!--CONTACT US FORM-->
<section id="contact">
<div class="containercontact">
<h2>Contact me</h2>
<div class="title-bar"></div>
<form action="" method="post" id="mycontactform">
<div class="left">
<input type="text" id="name" name="name" placeholder="Name" required="required"/>
<input type="email" id="email" name="email" placeholder="Email" required="required"/>
<input type="text" id="subject" name="subject" placeholder="Subject"/>
</div>
<div class="right">
<textarea placeholder="Message" id="message" name="message" required="required"></textarea>
</div>
<div class="send-button cl">
<button id="submit">Send Message</button>
</div>
</form>
</div>
</section>
这是我的PHP代码
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$to = 'example@example.com';
$message = <<<EMAIL
$subject
$message
From: $name
Email: $email
EMAIL;
$headers = 'From:' . $email;
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
mail($to, $subject, $message, $headers);
echo "Thank you for your email! We will reply as soon as possible.";
}
else
{
echo "Invalid Email, please provide a correct email address.";
}
?>
这是我的Jquery代码
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$('#submit').click(function(){
$.post("php/contactUs.php",
$("#mycontactform").serialize(),
function(response) {
alert("message sent!");
});
return false;
});
});
</script>
我根本无法让它工作。我 运行 它在我的 wamp 本地主机上,但仍然没有任何反应。
如有任何帮助,我们将不胜感激!
您的主机上有邮件服务器吗?
如果您不这样做,php 邮件功能将无法使用。
您将必须使用 google 的 smtp 服务器从您的 gmail
发送电子邮件
我有一个关于 github 的项目,如果你想告诉我的话
您不能使用本地主机的 email() 函数,它不会发送任何内容。
您需要一个有效的 SMTP 服务器。设置本地 SMTP 或使用第三方 SMTP 服务器。
我的网页上有一个联系我们表格,我正在使用 php 和 jquery 从联系我们表格发送数据。
当我填写数据时,我收到警报 "message sent",但我的电子邮件没有收到任何消息。
这是我的HTML代码
<!--CONTACT US FORM-->
<section id="contact">
<div class="containercontact">
<h2>Contact me</h2>
<div class="title-bar"></div>
<form action="" method="post" id="mycontactform">
<div class="left">
<input type="text" id="name" name="name" placeholder="Name" required="required"/>
<input type="email" id="email" name="email" placeholder="Email" required="required"/>
<input type="text" id="subject" name="subject" placeholder="Subject"/>
</div>
<div class="right">
<textarea placeholder="Message" id="message" name="message" required="required"></textarea>
</div>
<div class="send-button cl">
<button id="submit">Send Message</button>
</div>
</form>
</div>
</section>
这是我的PHP代码
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$to = 'example@example.com';
$message = <<<EMAIL
$subject
$message
From: $name
Email: $email
EMAIL;
$headers = 'From:' . $email;
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
mail($to, $subject, $message, $headers);
echo "Thank you for your email! We will reply as soon as possible.";
}
else
{
echo "Invalid Email, please provide a correct email address.";
}
?>
这是我的Jquery代码
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$('#submit').click(function(){
$.post("php/contactUs.php",
$("#mycontactform").serialize(),
function(response) {
alert("message sent!");
});
return false;
});
});
</script>
我根本无法让它工作。我 运行 它在我的 wamp 本地主机上,但仍然没有任何反应。
如有任何帮助,我们将不胜感激!
您的主机上有邮件服务器吗?
如果您不这样做,php 邮件功能将无法使用。
您将必须使用 google 的 smtp 服务器从您的 gmail
发送电子邮件我有一个关于 github 的项目,如果你想告诉我的话
您不能使用本地主机的 email() 函数,它不会发送任何内容。 您需要一个有效的 SMTP 服务器。设置本地 SMTP 或使用第三方 SMTP 服务器。