当我使用html和php通过表单发送邮件时,我发现了此错误。 我的代码:
<!doctype html>
<html>
<body>
<form method="post" action="#">
<input type='text' name='name'>
<input type='email' name="email">
<input type="number" name="mobile">
<input type="text" name="message">
<input type="submit" name='submit'>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
$mob = $_POST['mobile'];
$email = $_POST['email'];
$subject="Enquiry";
$query = $_POST['message'];
{
$cname = $_POST['name'];
$message="Name : $cname \n email : $email \n Message : $query \n";
$email_from = 'person2<person2@gmail.com.com>';
$subject = "registration";
$message = "You have received a new message from the user <b> $cname. </b> \n". "Here is the message:\n $message".
$to = "person1<person1@gmail.com>";
$headers = "From: $email_from \r\n";
$headers.= "Reply-To: $email \r\n";
ini_set("SMTP", "ssl://smtp.gmail.com");
ini_set("smtp_port", "587");
ini_set("sendmail_from", "person1@gmail.com");
if(mail($to, $subject, $message, $headers))
{
echo "<script>alert('Dear User, You Are Successfully Registered')</script>";
}
else
{
echo "It was a problem!";
}
}
?>
错误:
Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
我仅尝试了许多网站并回答了类似问题,但是我什么也听不懂。 谁能告诉我原因和解决方法?
答案 0 :(得分:0)
尝试再次连接到邮件服务器,并显示其检查php文件中的SMPT