我想在提交联系表单时使用PHP发送电子邮件..
这是我的index.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple PHP Contact Form</title>
<meta name="HandheldFriendly" content="true">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div class="wrapper">
<div id="contact_form">
<form name="form1" id="ff" method="post" action="insert.php">
<h1>Responsive HTML5 Contact Form Demo</h1>
<p>This is a working demo of HTML5 and PHP Responsive Contact Form. The form is so simple, that you can implement it in a few minutes.</p>
<label>
<span>Name*:</span>
<input type="text" placeholder="Please enter your name" name="name" id="name" required autofocus>
</label>
<label>
<span>City*:</span>
<input type="text" placeholder="Please enter your city" name="city" id="city" required>
</label>
<label>
<span>Phone:</span>
<input type="tel" placeholder="Please enter your phone" name="phone" id="phone">
</label>
<label>
<span>Email*:</span>
<input type="email" placeholder="youremail@gmail.com" name="email" id="email" required>
</label>
<input class="sendButton" type="submit" name="Submit" value="Send">
</form>
</div>
</div>
</body>
</html>
这是我的insert.php:
<?php
// Get values from form
$name=$_POST['name'];
$city=$_POST['city'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$to = "mymail@gmail.com";
$subject = "Future Tutorials Contact Form Test";
$message = " Name: " . $name . "\r\n City: " . $city . "\r\n Phone: " . $phone . "\r\n Email: " . $email;
$from = "FutureTutorials";
$headers = "From:" . $from . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
if(mail($to,$subject,$message,$headers))
{
print "Hello";
// Created by Future Tutorials
}else{
echo "Error! Please try again.";
}
?>
当我按下提交按钮时,它会显示以下错误消息
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
。但我在这里找不到错误的原因。
我在此省略的原始电子邮件。 感谢
答案 0 :(得分:0)
它写的是什么错误信息? 我建议你使用phpmailer。