0

When a person registers to my website, I am trying to add the registration to the database and then email them a confirmation. The database add works, but my program doesn't email them. Any idea where I'm going wrong?

<!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>
4

1 回答 1

0

您是否尝试使用本地主机等从您自己的网络服务器发送电子邮件?因为如果您想发送电子邮件,您还需要有一个邮件服务器。对我来说,我不想要本地邮件服务器,因此我创建了该功能并在站点的 prodserver 上对其进行测试。

于 2013-03-13T18:32:15.333 回答