我一直在用PHP做这个注册项目,但无论何时我在localhost上访问它(即时使用wampserver),它给我这个错误
发送电子邮件(由于错误而无法继续) 错误:警告:mail():无法连接到“localhost”端口25的邮件服务器,验证php.ini中的“SMTP”和“smtp_port”设置或使用ini_set()
我不确定错误是什么,因为这是我第一次尝试编写发送电子邮件的php文件。我希望有人可以帮助我
---这是我使用的代码(基于我看到的教程)
<?php
$to = "temblormariel@ymail.com";
$subject = 'SmoothTeamPH SignUp Registration';
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$pnum = $_POST['pnum'];
$shippingAdd = $_POST['shippingAdd'];
$body = <<<Email
Hi!
Smooth Team PH New Registration
First Name: $fname
Last Name: $lname
Email Address: $email
Phone Number: $pnum
Shipping Address: $shippingAdd
Thanks,
$lname, $fname
Email;
$header = "From: $email";
if($_POST){
if($lname == '' || $fname == '' || $email == '' || $pnum == '' || $shippingAdd == ''){
$feedback = 'Kindly fill out all the fields';
}else{
mail($to, $subject, $body, $header);
$feedback = "Thank you for providing your information. We will get back to you shortly";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Smooth Team PH Inc</title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<div id="container">
<header id="header">
<div id="menu" class="menu">
<ul>
<li><a href="#" target="_blank"> HOME </a></li>
<li><a href="#" target="_blank"> SIGN UP </a></li>
<li><a href="#" target="_blank"> ABOUT US </a></li>
<li><a href="#" target="_blank"> CONTACT </a></li>
</ul>
</div>
</header>
<section id="content">
<h2>Sign Up</h2>
<div id="signup">
<form action="?" method="post">
<ul>
<li>
<label for="fname">First Name : </label>
<input type="text" name="fname" id="fname" />
</li>
<li>
<label for="lname">Last Name : </label>
<input type="text" name="lname" id="lname" />
</li>
<li>
<label for="email">Email : </label>
<input type="text" name="email" id="email" />
</li>
<li>
<label for="pnum"> Phone Number : </label>
<input type="text" name="pnum" id="pnum" />
</li>
<li>
<label for="shippingAdd">Shipping Address : </label>
<textarea id="shippingAdd" name="shippingAdd" cols="42" rows="9"></textarea>
</li>
<li>
<input type="submit" value="Submit">
</li>
</ul>
<p id="feedback"> <?php echo $feedback; ?> </p> <!-- will be transfered to 2nd page later -->
</form>
</div>
</section>
<footer id="footer">
<div id="fmenu" class="fmenu">
<p>©2015 smoothteamphinc | Design & Development by Mariel Temblor</p>
</footer>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
对于我的问题,这就是我所做的
错误1:而不是
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$pnum = $_POST['pnum'];
$shippingAdd = $_POST['shippingAdd'];
我做了
$fname = isset($_POST['fname']) ? $_POST['fname'] : '';
$lname = isset($_POST['lname']) ? $_POST['lname'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$pnum = isset($_POST['pnum']) ? $_POST['pnum'] : '';
$shippingAdd = isset($_POST['shippingAdd']) ? $_POST['shippingAdd'] : '';
错误2:我在if statemate之外添加了另一个变量声明。并将其添加到$ header声明之上。并在其中分配了一个空值。
$feedback = "";
$header = "From: $email";
错误3:
我们真的无法找到解决这个问题的最佳方法,因为它是电子邮件,而且我真的不知道要把什么放在smtp上,所以我的朋友让我借用他的域名,以便我可以在至少检查代码是否正常工作。是的,确实如此。我收到了我的$ to code的电子邮件。
我希望这对那些经历同样事情的人有所帮助。特别感谢我的朋友:)