我创建了一个表单和php来将表单详细信息发送到我的电子邮件。但是,当通过 localhost 通过 wampserver 运行网页时,它会显示一个错误"警告:mail((:无法连接到"localhost"端口 25 的邮件服务器,验证 php 中的"SMTP"和"smtp_port"设置.ini或在 C:\wamp\www\My original web\PHP\ContactUs.php 第 22 行中使用 ini_set((。我找不到第 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
}
?>
选择是使用PHPmailer,这将允许您正确发送邮件并节省大量时间。
如何使用PHPMailer本教程将指导您。
你应该使用标题。您可以使用任何第三方服务器测试工具来测试本地主机中的邮件。例如:-"测试邮件服务器工具">
<?php
$admin_email = "pinkmaidbeautysalon@gmail.com";
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message = $_REQUEST['message'];
if(!empty($email))
{
$headers = 'From:'.'pinkmaidbeautysalon@gmail.com' . "rn" .
'Reply-To: Pink maid beauty saloon <pinkmaidbeautysalon@gmail.com>' . "rn" .
'X-Mailer: PHP/' . phpversion() . "rn" .
'Content-type: text/html; charset=iso-8859-1';
//mail (from,subject,body,headers)
mail($admin_email,"Your saloon", "$name "."$phone "."$message", $headers);
echo "Email successfully sent";
}
mysqli_close($con);
?>