我正在制作联系表格,以便有人可以向指定的电子邮件发送消息。但是,我收到一条非常持久且不会消失的错误消息:
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() in C:\wamp\www\mail.php on line 10
我尝试按照指定在第 10 行放入 ini_set() ,但是它没有改变任何东西。我试图研究可能是什么情况,但到目前为止还没有遇到任何事情。我在想也许 WAMP 不支持邮件。
HTML 代码
<form action = "mail.php" method= "POST">
<p>Name</p> <input name = "name" type = "text">
<p>Email</p> <input name = "email" type = "text">
<p>Message</p><textarea name = "message" rows = "6" cols = "25"></textarea><br />
<input value = "Send" type = "submit" >
<input value = "Reset Form" type = "reset">
</form>
成功制作表单的地方,通过提交按钮将数据发送到 mail.php。
PHP 代码
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$recipient = "To: myawesome.email@gmail.com";
$mailheader = "From: $name \r\n";
$formcontent= "From: $email \r\n Message: $message";
mail($recipient, $mailheader, $formcontent) or die("Error!");
echo "Your message has been delivered." . " -" . "<a href='form.html' style='text-decoration: none; color: #ff0099;'> Return Home </a>";
?>
mail.php 应该接收 $recipient、$mailheader 和 $formcontent 并将它们通过电子邮件发送到指定地址。
任何帮助深表感谢。