please help me! check my PHP email form
Posted: Sun Dec 10, 2006 3:04 am
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi guys
i am new here
i have designed am email form in php and need some help
i want the alert message box if someone doesnt enter in the required field rather than the echo...
in my php code name, email, subject, inquiry and message are required fields..
plz help see my form at http://www.sharebigfile.com/file/35140/Inquiry.php.html
or see the code below
plz help me guys
thnx in advance
JackCode: Select all
<html>
<body>
<?php
// declare values
$contact_email = $_POST['EmailAddress'];
$contact_subject = $_POST['Subject'];
$contact_name = $_POST['FullName'];
$contact_company = $_POST['Company'];
$contact_address = $_POST['Address'];
$contact_tel = $_POST['Tel'];
$contact_fax = $_POST['Fax'];
$contact_inquiry = $_POST['Inquiry'];
$contact_message = $_POST['Message'];
$mydate = date ( 'l, F d Y g:i A',time()+240 );
// where to send e-mail to
$to = 'info@saqadgifts.com';
// e-mail subject
$subject = "Inquiry from website.";
// e-mail message
$message = "You have received an Inquiry:\r\n"
."----------------------------------------------------------------\r\n"
."Contact Name: $contact_name\r\n"
."Subject: $contact_subject\r\n"
."Company: $contact_company\r\n"
."Address: $contact_address\r\n"
."Tel: $contact_tel\r\n"
."Fax: $contact_fax\r\n"
."Inquiry: $contact_inquiry\r\n"
."Comments: $contact_message\r\n"
."Submitted: $mydate\r\n"
."From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Form Address: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
$headers = "From: $contact_name <$contact_email>\n"
."Reply-To: $contact_email\n"
."Company: $contact_company\n"
."Address: $contact_address\n"
."Tel: $contact_tel\n"
."Fax: $contact_fax\n"
."Inquiry: $contact_inquiry\n"
."X-Mailer: PHP/".phpversion();
// check for validation, then send the e-mail
if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_inquiry) || empty($contact_message)) {
echo '<p>Send us an Inquiry, enter your information below and click \'Submit\'!</p>
<form method="post" action="">
<table id="Form-Details" width="429">
<tbody>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Name:</b></font></td><td width="357">
<input type="text" name="FullName" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Subject:</b></font></td><td width="357">
<input type="text" name="Subject" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Email:</b></font></td><td width="357">
<input type="text" name="EmailAddress" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Company:</b></font></td><td width="357">
<input type="text" name="Company" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Address:</b></font></td><td width="357">
<textarea rows="3" name="Address" cols="43" style="border-style: solid; border-width: 1px"></textarea></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Tel.:</b></font></td><td width="357">
<input type="text" name="Tel" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Fax:</b></font></td><td width="357">
<input type="text" name="Fax" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62"><font face="Tahoma" color="#800080"><b>Inquiry:</b></font></td><td width="357">
<input type="text" name="Inquiry" size="57" style="border-style: solid; border-width: 1px" /></td></tr>
<tr><td width="62" valign="top"><font face="Tahoma" color="#800080"><b>Comments:</b></font></td><td width="357">
<font face="MS Sans Serif">
<textarea rows="5" name="Message" cols="43" class="input" style="border-style: solid; border-width: 1px"></textarea></font></td></tr>
<tr><td width="81"> </td><td width="405">
<input type="submit" value="Submit" style="font-family: Tahoma; font-weight: bold; float:left" /><font face="Tahoma"><input type="reset" value="Reset" style="font-family: Tahoma; font-weight: bold; float:left" /></font></td></tr>
</tbody>
</table>
</form>';
} elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
echo "<p>ERROR: Please enter a valid e-mail address.</p>";
} else {
mail( $to, $subject, $message, $headers );
echo "<h3>Message Sent!</h3><p>Dear $contact_name,<br /><br />We will get back to you as soon as possible using $contact_email.";
}
?>
</body>
</html>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]