Jump to content

PHP Mail Form Issue


john.grisum
 Share

Recommended Posts

I have one issue that occurs with my PHP Mail form on my site (PHP code below) and I have one feature I would like to add. 1. The error occurs when I take away the "'mep'" out of the "$required = array". When I do this and the email is sent to my server, that information line does not show in the email. You can see my form here: www.freemyblackberry.com/freecodeAll fields must be filled out by the customer, except the 'mep' field where it is optional. How do I get it to show in the email?2. I would like to have the information in the email field show up as the subject when the email is sent to my server. How would I go about that?

<?phpif(!$_POST) exit;$email = $_POST['email'];//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Please make sure you have entered a valid email address."; $errors=1;}if($errors==1) echo $error;else{ $values = array ('email','imei','model', 'carrier', 'mep', 'country'); $required = array('email','imei', 'model', 'carrier', 'mep','country'); $your_email = "blank for security"; $email_subject = "Unlock Code Request: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Unlock Code Request Sent!'; } else { echo 'ERROR!'; }}?>
HTML----------------------
...jQuery(document).ready(function(){ $('#contactform').submit(function(){ var action = $(this).attr('action'); $.post(action, { email: $('#email').val(), imei: $('#imei').val(), model: $('#model').val(), carrier: $('#carrier').val(), mep: $('#mep').val(), country: $('#country').val() }, function(data){ $('#contactform #submit').attr('disabled',''); $('.response').remove(); $('#contactform').before('<p class="response">'+data+'</p>'); $('.response').slideDown(); if(data=='Unlock Code Request Sent!') $('#contactform').slideUp(); } ); return false; });});// ]]></script>....<strong>Required fields are marked by *</strong><br /> </p> <form action="freecode.php" method="post" name= "contactform" id="contactform"> <ol> <li> <label for="email">Email<span class="red">* </label> <input id="email" name="email" type="text" class="text" value="Example: person@yahoo.com" onfocus="this.value=''"/> </li> <li> <label for="imei">IMEI Number<span class="red">*</span> <br> (no periods please) </label> <input id="imei" name="imei" type="text" class="text" value="Example: 123456789012345" onfocus="this.value=''"/> </li> <li> <label for="model">BlackBerry Model Number<span class="red">* </label> <input id="model" name="model" type="text" class="text" value="Example: 9700" onfocus="this.value=''"/> </li> <li> <label for="carrier">Mobile Carrier/Network <span class="red">* </label> <input id="carrier" name="carrier" type="text" class="text" value="Example: Rogers" onfocus="this.value=''"/> </li> <li> <label for="mep">MEP Number <span class="red"> (optional)</span><br>(<a href="mepcode.html"><span><strong> What is my MEP number?</span></strong></a>)</label> <input id="mep" name="mep" type="text" class="text" value="Example: MEP-09292-093" onfocus="this.value=''" /> </li> <li> <label for="country">Country<span class="red">* </label> <input id="country" name="country" type="text" class="text" value="Example: Canada" onfocus="this.value=''"/> </li> <li class="buttons"> <input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" /> <div class="clr"></div> </li> </ol> </form>...
Edited by john.grisum
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...