0

ある人が私の Web サイトに登録すると、その登録をデータベースに追加してから、確認メールを送信しようとしています。データベースの追加は機能しますが、私のプログラムはメールを送信しません。どこが間違っているのか分かりますか?

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

ローカルホストなどを使用して、独自の Web サーバーから電子メールを送信しようとしていますか? 電子メールを送信する場合は、メールサーバーも必要になるためです。私にとっては、ローカルのメールサーバーは必要ないので、関数を作成し、サイトの prodserver でテストします。

于 2013-03-13T18:32:15.333 に答える