当一个人注册到我的网站时,我正在尝试将注册添加到数据库,然后通过电子邮件向他们发送确认。数据库添加有效,但我的程序不会通过电子邮件发送它们。知道我哪里错了吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="main">
<?php
{
include "base.php"; //connect to database
if(isset($_POST['register'])){
$email = mysqli_real_escape_string($_SESSION['base'], $_POST['email']);
$password = md5(mysqli_real_escape_string($_SESSION['base'], $_POST['password']));
$firstname = mysqli_real_escape_string($_SESSION['base'], $_POST['firstName']);
$lastname = mysqli_real_escape_string($_SESSION['base'], $_POST['lastName']);
$addressline1 = mysqli_real_escape_string($_SESSION['base'], $_POST['addressLine1']);
$addressline2 = mysqli_real_escape_string($_SESSION['base'], $_POST['addressLine2']);
$city = mysqli_real_escape_string($_SESSION['base'], $_POST['city']);
$county = mysqli_real_escape_string($_SESSION['base'], $_POST['county']);
$postcode = mysqli_real_escape_string($_SESSION['base'], $_POST['postCode']);
$phoneno = mysqli_real_escape_string($_SESSION['base'], $_POST['phoneNo']);
$checkemail = mysqli_query($_SESSION['base'], "SELECT * FROM Users WHERE Email = '".$email."'");
}
if(mysqli_num_rows($checkemail) == 1) {
?>
<h1>Register</h1>
<p>Please enter your details below to register.</p>
<form action='register.php' method='post' name='registerform' id='registerform'>
<label for='email'>Email:</label><input type='text' name='email' id='email' /><br />
<label for='password'>Password:</label><input type='password' name='password' id='password' /><br />
<label for='firstname'>First Name:</label><input type='text' name='firstName' id='firstName' /><br />
<label for='lastname'>Last Name:</label><input type='text' name='lastName' id='lastName' /><br />
<label for='addressline1'>Address Line 1:</label><input type='text' name='addressLine1' id='addressLinel' /><br />
<label for='addressline2'>Address Line 2:</label><input type='text' name='addressLine2' id='addressLine2' /><br />
<label for='city'>City:</label><input type='text' name='city' id='city' /><br />
<label for='county'>County:</label><input type='text' name='county' id='county' /><br />
<label for='postcode'>Postcode:</label><input type='text' name='postCode' id='postCode' /><br />
<label for='phoneno'>Phone no:</label><input type='text' name='phoneNo' id='phoneNo' /><br />
<input type='submit' name='register' id='register' value='Register' />
</form>
<?php
echo "<h1>Error</h1>";
echo "<p>Sorry, that Email is taken. Please go back and try again.</p>";
}
else
{
$registerquery = mysqli_query($_SESSION['base'], "INSERT INTO Users (Email, Password, FirstName, LastName, AddressLine1, AddressLine2, City, County, PostCode, PhoneNo)
VALUES('".$email."', '".$password."', '".$firstname."', '".$lastname."', '".$addressline1."', '".$addressline2."', '".$city."', '".$county."', '".$postcode."', '".$phoneno."')");
if($registerquery)
{
$to = "email";
$subject = "Email Verification mail";
$headers = "From: cameron@abandoned \r\n";
$headers .= "Reply-To: cameron@abandoned.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message.='<div style="width:550px; background-color:#CC6600; padding:15px; font- weight:bold;">';
$message.='Email Verification mail';
$message.='</div>';
$message.='<div style="font-family: Arial;">Confiramtion mail have been sent to your email id<br/>';
$message.='hello cameron ';
$message.='</div>';
$message.='</body></html>';
mail($email,$subject,$message,$headers);
}
echo "<h1>Success</h1>";
echo "<p>Your account was successfully created. Please <a href=\"index.php\">click here to login</a>.</p>";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your registration failed. Please enter your details again. </p>";
}
}
}
else{
?>
<h1>Register</h1>
<p>Please enter your details below to register.</p>
<form action='register.php' method='post' name='registerform' id='registerform'>
<label for='email'>Email:</label><input type='text' name='email' id='email' /><br />
<label for='password'>Password:</label><input type='password' name='password' id='password' /><br />
<label for='firstname'>First Name:</label><input type='text' name='firstName' id='firstName' /><br />
<label for='lastname'>Last Name:</label><input type='text' name='lastName' id='lastName' /><br />
<label for='addressline1'>Address Line 1:</label><input type='text' name='addressLine1' id='addressLinel' /><br />
<label for='addressline2'>Address Line 2:</label><input type='text' name='addressLine2' id='addressLine2' /><br />
<label for='city'>City:</label><input type='text' name='city' id='city' /><br />
<label for='county'>County:</label><input type='text' name='county' id='county' /><br />
<label for='postcode'>Postcode:</label><input type='text' name='postCode' id='postCode' /><br />
<label for='phoneno'>Phone no:</label><input type='text' name='phoneNo' id='phoneNo' /><br />
<input type='submit' name='register' id='register' value='Register' />
</form>
<?php
?>
<html>
<?php
}
?>
</div>
</body>
</html>
答案 0 :(得分:0)
您是否尝试使用localhost和所有这些来自您自己的网络服务器发送电子邮件?因为如果你想发送电子邮件,你还需要有一个邮件服务器。对我来说,我不想要一个本地邮件服务器,所以我创建了该函数并在该网站的prodserver上测试它。