Reputation: 75
<!DOCTYPE html>
<html>
<head>
<link href="aadab.css" rel="stylesheet" type="text/css">
<link rel="icon" href="images/favicon.png">
</head>
<body>
<h2>REGISTRATION FORM</h2>
<div id="form">
<?php
if(isset($_POST['submit']))
{
$name= $_POST['name'];
$phone= $_POST['phone'];
$email= $_POST['email'];
$college= $_POST['namecolg'];
$team= $_POST['team'];
$im= $_POST['im'];
$detail= $_POST['detail'];
$subject= 'Registration for aadab 2013';
if ( (empty($name)) || (empty($phone)) || (empty($email)) || (empty($college)) || (empty($detail)) )
{
echo '<p id="fillall">It is necessary that you fill at least the required fields that are marked with a star</p>';
}
else
{
$to= '[email protected]';
$con= "<b>Registration Details:</b><br>"."Name: $name<br>"."Contact: $phone<br>"."Email: $email<br>"."College: $college<br>"."Team(if any): $team<br>"."Instant message: $im<br>"."Details of the event(s): $detail<br>";
$emsg= "Registration Details:\n\n"."Name: $name\n"."Contact: $phone\n"."Email: $email\n"."College: $college\n"."Team(if any): $team\n"."Instant message: $im\n"."Details of the event(s): $detail\n";
$msg = wordwrap($emsg,70);
$mailsend= mail($to, $subject, $msg);
if ($mailsend)
{
echo "<div class=\"regdet\"><b>Here is what you've submitted:</b><br><br>$con";
echo '<br>Congratulations! You have successfully registered! Click <a href="index.html">here</a> to continue.</div>';
}
else
{
echo '<div class="regdet"><br>OOPS! Something went wrong. Click <a href="form.php">here</a> to try again.</div>';
}
}
}
else
{?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" autocomplete="on" method="post">
<table>
<tr>
<th><label for="name">Your fullname*</label></th>
<td><input type="text" id="name" name="name" value="<?php echo $name; ?>" required></td>
</tr>
<tr>
<th><label for="phone">Your contact number*</label></th>
<td><input type="tel" id="phone" name="phone" value="<?php echo $phone; ?>" required></td>
</tr>
<tr>
<th><label for="email">Your email-id*</label></th>
<td><input type="email" id="email" name="email" value="<?php echo $email; ?>" required></td>
</tr>
<tr>
<th><label for="namecolg">Name of your college*</label></th>
<td><input type="text" id="namecolg" name="namecolg" value="<?php echo $college; ?>" required></td>
</tr>
<tr>
<th><label for="team">The name of your team<br>(if registering for a team event)</label></th>
<td><input type="text" id="team" name="team" value="<?php echo $team; ?>" ></td>
</tr>
<tr>
<th><label for="im">Bbm pin/iMessage id/Whatsapp<br>(if any, separate each id by a comma)</label></th>
<td><input type="text" id="im" name="im" value="<?php echo $im; ?>" ></td>
</tr>
<tr>
<th><label for="detail">Details of the event(s) you want to register for*</label></th>
<td><input type="text" id="detail" name="detail" value="<?php echo $detail; ?>" required></td>
</tr>
<tr><td colspan="2" style="text-align: center; padding: 40px 0px 0px 0px;"><input type="submit" name="submit" value="Register"></td</tr>
</table>
</form>
<?php } ?>
</div>
</body>
</html>
this piece of script has baffled me for two days ! i am unable to find a bug which is not allowing me to send an email to my email id
firebug also does not show any warnings or error i checked phpcodechecker.com for possible syntax errrors but nothing came up
im unable to receive maill from neither a live server nor my local zend server in both cases i get the "else" echo statement..
Upvotes: 2
Views: 2461
Reputation: 2269
If you know for a fact that mail is setup and allowed on your server, try sending a test email just to make sure your variables aren't creating the error. Do something like this:
$test = mail('[email protected]', 'Test Email', 'Hope this works!');
if ( $test ) { echo 'Yay it worked!'; }
else { echo 'Oh no mail failed!'; }
If you do not know for a fact that mail is setup and enabled, then do the following:
First, run phpinfo();
and see what the path to your php.ini file is. Next, look for a line that says disabled_functions
and see if it contains the word mail
. If it does, simply remove the mail
keyword from this line and it will enable the mail() function. If you are unable to access your php.ini, you may wish to contact your webhost and ask if they can manually enable it for you.
However, if no send-path has been setup, it will be a lot harder to get mail() to work. If this is the case, you may want to look into using a 3rd party mailer, such as SwiftMailer. Personally, I use SwiftMailer even though php's mail() function is enabled for me. It makes headers and other things easier, in my opinion.
UPDATE BASED ON FAILED mail() FUNCTION:
In this case, run phpinfo();
and look in the 6th row. It should say Configuration File (php.ini) Path
. Then use the supplied path to display the contents of the php.ini file by doing this:
echo str_replace("\n", '<br />', file_get_contents('/PATH_TO_CONFIG/php.ini'));
Now, just replace PATH_TO_CONFIG with the path supplied in by the phpinfo()
function. Alternatively, you can rely on the php_ini_loaded_file()
function to return the path and retrieve it that way. So you could also do this:
echo str_replace("\n", '<br />', file_get_contents(php_ini_loaded_file()));
Then, search the document for disabled_functions
and see if mail
is in there. If not, I would guess that a send-path has not been setup on your server.
UPDATE FOR WIN64: Try putting this in your configuration:
[mail function]
SMTP = mail.yourdomain.com
sendmail_from = [email protected]
Upvotes: 2
Reputation: 26
First of all mail()
function isn't able to check if the e-mail reached the mailbox.
But your script returned a false on mail()
so its something on the serverside.
And yes, take a look at phpinfo()
for disabled functions on both servers.
Sometimes you aren't allowed to send a mail if you're on a shared server.
most likely you can't send mail from a local domain to another mail server because this may be an unqualified or illegal domain (will be marked as spam)
and last but not least, download a phpmailer class, its much easier to use and you don't have to worry much about mail-headers
Upvotes: 1
Reputation: 94
This is the function for sending mail in PHP:
mail(to,subject,message,headers,parameters)
to
, subject
and message
are all required parameters. You are missing a subject.
headers
and parameters
are optional
For additional details on how to use the mail()
function, see: http://php.net/manual/en/function.mail.php
Upvotes: 0