What I want the form to do is that when the user presses the submit button, the form is processed and the user is sent an email with their username and password serving as a confirmation of registration to them.
The user's details are entered into the database.
My problem here is that I want the email address to be entered into the mail() function using $_POST, but the mail() function doesn't seem to work. It keeps coming up with an error message telling me to enter a valid email address.
I am including the code for the form:
Code: Select all
<?php
include "session.php"; ?>
<html>
<title>Registration Page</title>
<?php include "menu.php";?>
<H2 align="center">
<BR>
<font face = "Arial" style ="font-size:20pt" color="#0B3A62">Register with Capital Abode</font></H2></BR>
<body>
<?
/**
* The user has submitted the registration form and the
* results have been processed.
*/
if(isset($_SESSION['regsuccess'])){
/* Registration was successful */
if($_SESSION['regsuccess']){
echo "<h1>Registered!</h1>"; ?>
<font face = "Arial" style ="font-size:12pt" color="#0B3A62">
<?
echo "<p>Thank you <b>".$_SESSION['reguname']."</b>, a confirmation of registration has been sent to your registered email address."
." You may now <a href=\"main.php\">log in</a>.</p>"; ?>
</font>
<?
$email = addslashes($_POST['userEmail']);
$first = addslashes($_POST['userFirstName']);
$to = $email;
$subject = 'Registration Confirmation';
$body = 'Hello'.$first.', Thank you for registering with Capital Abode.';
$headers = 'From: noreply@capitalabode.com' . "\r\n";
mail($to, $subject, $body, $headers);?>
<?
}
/* Registration failed */
else{
?><font face = "Arial" style ="font-size:22pt" color="#0B3A62"><?
echo "<h1>Registration Failed</h1>";?>
<font face = "Arial" style ="font-size:12pt" color="#0B3A62">
<?
echo "<p>We're sorry, but an error has occurred and your registration for the username <b>".$_SESSION['reguname']."</b>, "
."could not be completed.<br>Please try again at a later time.</p>"; ?>
</font>
<?
}
unset($_SESSION['regsuccess']);
unset($_SESSION['reguname']);
}
/**
* The user has not filled out the registration form yet.
* Below is the page with the sign-up form, the names
* of the input fields are important and should not
* be changed.
*/
else{
?>
<?
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST">
<table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td><font face = "Arial" style ="font-size:11pt" color="#0B3A62">Username:</td><td><input type="text" name="username" maxlength="30" value="<? echo $form->value("username"); ?>"></td><td><? echo $form->error("username"); ?></font></td></tr>
<tr><td><font face = "Arial" style ="font-size:11pt" color="#0B3A62">First Name:</td><td><input type="text" name="userFirstName" maxlength="30" value="<? echo $form->value("userFirstName"); ?>"></td><td><? echo $form->error("userFirstName"); ?></font></td></tr>
<tr><td><font face = "Arial" style ="font-size:11pt" color="#0B3A62">Last Name:</td><td><input type="text" name="userLastName" maxlength="30" value="<? echo $form->value("userLastName"); ?>"></td><td><? echo $form->error("userLastName"); ?></font></td></tr>
<tr><td><font face = "Arial" style ="font-size:11pt" color="#0B3A62">Email:</td><td><input type="text" name="userEmail" maxlength="50" value="<? echo $form->value("userEmail"); ?>"></td><td><? echo $form->error("userEmail"); ?></font></td></tr>
<tr><td><font face = "Arial" style ="font-size:11pt" color="#0B3A62">Password:</td><td><input type="password" name="userPassword" maxlength="30" value="<? echo $form->value("userPassword"); ?>"></td><td><? echo $form->error("userPassword"); ?></font></td></tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subjoin" value="1">
<input type="submit" name = "submit" value="Join!"></td></tr>
<tr><td colspan="2" align="left"><a href="index.php"><font face = "Arial" style ="font-size:12pt" color="#0B3A62">Back to Home</font></a></td></tr>
</table>
</form>
<?
}
?>
</body>
</html>
Thanks.