[英]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()
I want to send an Email using PHP when a contact form is submitted .. 我想在提交联系表单时使用PHP发送电子邮件。
Here's my index.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>
Here's my insert.php: 这是我的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.";
}
?>
When I press the submit button it shows the following Error Message 当我按下提交按钮时,它显示以下错误消息
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()
. 。 But I couldn't find the cause of the error here.
但我在这里找不到错误的原因。
The original email I have omitted here. 我在这里省略了原始电子邮件。 Thanks
谢谢
what error message it writes? 它写的是什么错误信息? I recommend you to use phpmailer.
我建议你使用phpmailer。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.