环境:xammp;Mercury 用的25端口;
PHP:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>boot</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/jquery.js"></script>
<style>
.contact-form{
border: 1px solid #c0c0c0;
margin-top: 30px;
border-radius: 10px;
box-shadow: 3px 3px 16px #c0c0c0;
}
.head{
height: 85px;
}
.head p{
font-size: 40px;
line-height: 85px;
}
.alert p{
font-style: italic;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-offset-1 col-sm-10 contact-form">
<div class="head">
<p>Contact Us</p>
</div>
<?php
function _post($str){
$val = !empty($_POST[$str]) ? $_POST[$str] : null;
return $val;
}
$name=_post("name");
$email=_post("email");
$message=_post("message");
$errors='';
$missing_name ='<p>Please enter your name!</>';
$missing_email ='<p>Please enter your Email!</>';
$invalid_email ='<p>Please enter your <strong>Valid</strong> Email!</>';
$missing_message ='<p>Please enter your Messages!</>';
if (_post("submit")){
if (!$name){
$errors.=$missing_name;
}else{
$name=filter_var($name, FILTER_SANITIZE_STRING);
}
if (!$email){
$errors.=$missing_email;
}else{
$email=filter_var($email, FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$errors.=$invalid_email;
}
}
if (!$message){
$errors.=$missing_message;
}else {
$message=filter_var($message, FILTER_SANITIZE_STRING);
}
if ($errors){
$resultMessage='<div class="alert alert-danger">'.$errors.'</div>';
}else{
$to = "[email protected]";
$subject ="Contact";
$message ="
<p>Name: $name</p>
<p>Email: $email</p>
<p>Messages:</p>
<p><strong>$message</strong></p>
";
$headers = "Content-type:text/html";
if (mail($to, $subject, $message, $headers)){
$resultMessage='<div class="alert alert-success">Thanks For Your Message.</div>';
}else{
$resultMessage='<div class="alert alert-warning">Web Error.</div>';
}
}
echo $resultMessage;
}
?>
<form method="post">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" name="name" id="name" placeholder="Name" class="form-control" value="<?php echo _post("name"); ?>">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email" placeholder="Email" class="form-control" value="<?php echo _post("email"); ?>">
</div>
<div class="form-group">
<label for="name">Message:</label>
<textarea name="message" id="message" class="form-control" rows="5"><?php echo _post("message"); ?></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" id="submit" class="btn btn-success btn-lg" value="Send Message">
</div>
</form>
</div>
</div>
</div>
<script src="js/bootstrap.js"></script>
</body>
</html>
PHP.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=localhost
; http://php.net/smtp-port
smtp_port=25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
Mercury的Do not permit 已经取消勾选;
试了三五个邮箱了,始终不可以。
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…