【发布时间】:2021-02-08 12:19:33
【问题描述】:
当我使用 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()
我尝试了许多网站并回答了类似的问题,但我什么都不懂。 谁能告诉我原因和解决方法?
【问题讨论】:
-
您可以不使用
ini_set()发送电子邮件,您应该查看您的php.ini 并更改您的smtp 设置 -
实际上,在我尝试仅在没有电子邮件的情况下发送但该错误说使用
ini_set()之前。顺便感谢你们两位,我会尝试在 php.ini 中更改我的设置。