如何使用PHP发送电子邮件?
以下是HTML: 我从一个网站得到它,它带来了更多的jQuery和CSS。所以,我想知道为什么它不会发送电子邮件。 PHP低于HTML。 JavaScript将是一个jsfiddle,因为它很多。它附带:名称,电子邮件和消息,我也尝试添加电话号码,这可能是一个问题。我已经尝试了很多,但我无法弄明白。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/bootstrap2.min.css">
<link rel="stylesheet" href="css/animateform.css">
</head>
<body>
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<div class="well" style="margin-top: 10%;">
<h3>Send me a message</h3>
<form role="form" id="contactForm" data-toggle="validator" class="shake">
<div class="row">
<div class="form-group col-sm-6">
<label for="name" class="h4">Name</label>
<input type="text" class="form-control" id="name" placeholder="Enter name" required data-error="NEW ERROR MESSAGE">
<div class="help-block with-errors"></div>
</div>
<div class="form-group col-sm-6">
<label for="email" class="h4">Email</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group col-sm-6">
<label for="phone" class="h4">Phone</label>
<input type="phone" class="form-control" id="phone" placeholder="Enter Phone" required>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<label for="message" class="h4 ">Message</label>
<textarea id="message" class="form-control" rows="5" placeholder="Enter your message" required></textarea>
<div class="help-block with-errors"></div>
</div>
<button type="submit" id="form-submit" class="btn btn-success btn-lg pull-right ">Submit</button>
<div id="msgSubmit" class="h3 text-center hidden"></div>
<div class="clearfix"></div>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="Java/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="Java/validator.min.js"></script>
<script type="text/javascript" src="Java/form-scripts.js"></script>
</body>
</html>
现在这里是PHP代码,我的电子邮件已被删除(原因很明显)。
<?php
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
$errorMSG = "Name is required ";
} else {
$name = $_POST["name"];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST["email"];
}
// PHONE
if (empty($_POST["phone"])) {
$errorMSG .= "Phone is required ";
} else {
$phone = $_POST["phone"];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG .= "Message is required ";
} else {
$message = $_POST["message"];
}
$EmailTo = "erased@gmail.com";
$Subject = "New Message Received";
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Something went wrong :(";
} else {
echo $errorMSG;
}
}
?>
以下是JavaScript:
validator.min.js:http://jsfiddle.net/4yujfv7L/
形状scripts.js中 http://jsfiddle.net/tnz3so04/
以下是CSS文件: 没关系,我刚开始问这里,所以我不能发布两个以上的链接。