【发布时间】:2017-10-28 01:25:26
【问题描述】:
我创建了一个表单和 php 以将表单详细信息发送到我的电子邮件。但是,当通过 localhost 通过 wampserver 运行网页时,它会显示错误为“警告:邮件():无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用C:\wamp\www\My original web\PHP\ContactUs.php 中的 ini_set() 第 22 行"。我找不到第 22 行的错误。
<div class="container">
<form name="htmlform" method="POST" action="../PHP/ContactUs.php">
<label for="name">Name</label>
<input type="text" id="name" name="name" placeholder="Your Name">
<label for="email">Email Address</label>
<input type="text" id="email" name="email" placeholder="Your Email Address">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="Your Phone Number">
<label for="Message">Message</label>
<textarea id="message" name="message" placeholder="Write You Something" style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "pinkmaidbeautysalon@gmail.com";
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message = $_REQUEST['message'];
//send email
mail($admin_email, "$name", "$phone", "$message", "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<?php
}
?>
【问题讨论】:
-
与其使用
$_REQUEST(可以同时使用$_POST 和$_GET 方法),不如使用$_POST。该错误表明您正在开发系统上尝试此操作并且没有运行邮件服务器 -
@RamRaider 如何设置邮件服务器?
-
这是一个相当广泛的主题,当 php 脚本将托管在反正以后上网?我会在 php 代码中添加一些逻辑,以检查您是否在
localhost上运行,如果是,则不发送电子邮件。或者,尝试搜索"free mail server for windows"或查看stackoverflow.com/questions/16830673/… ~ 那里有很多解决方案 -
@RamRaider 不使用邮件服务器,是否无法将详细信息发送到电子邮件?
-
是的 - 你需要一个邮件服务器来发送电子邮件