# PHP Mail form - changing mandatory field into optional

**URL:** <https://forum.kirupa.com/t/php-mail-form-changing-mandatory-field-into-optional/222391>\
**Category:** programming\
**Created:** [April 12, 2007, 11:35pm UTC](https://forum.kirupa.com/t/php-mail-form-changing-mandatory-field-into-optional/222391 "2007-04-12T23:35:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![flasherkirupa](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@flasherkirupa](https://forum.kirupa.com/u/flasherkirupa)\
**Post date:** [April 12, 2007, 11:35pm UTC](https://forum.kirupa.com/t/php-mail-form-changing-mandatory-field-into-optional/222391/1 "2007-04-12T23:35:32Z")

</div>

I would like to make an email field to be optional -  
could you help in modifying this code?

\<?php  
$emailku="user@yahoo.com"; // your email address to send to  
$validResponse=“Thank you for your interest in our company. We will respond to your request shortly.”; // your response message appeared in flash after sending  
$nonValidResponse=“INVALID EMAIL FORMAT. PLEASE TRY AGAIN …”;

$regex="^([a-zA-Z0-9.\_-]+)@([a-zA-Z0-9-])+(.[a-zA-z0-9-]+)+$";  
$email=strtolower($email);  
$subjectEmail = “website mail[$name1]”;

```
$messageTotal = "First Name : $name1
Last Name : $name2

Address : $address
City : $city
State : $state1
Zip : $zip

Email : $email
Phone : $phone

How did you hear about us? : $hear

Additional Comments? : $help

Points of interest : $villa
";

mail($emailku,$subjectEmail,$messageTotal,"From:$email

```

Reply-to: $email  
“);  
//add and change email to send copy to another address  
//mail("myother@email.com”,$subjectEmail,$messageTotal,"From:$email  
Reply-to: $email  
");

print “&answer=”.urlencode($validResponse);

?\>

Here is my Actionscript:

stop();

sta="";  
name1.tabIndex = 1;  
name2.tabIndex = 2;  
address.tabIndex = 3;  
city.tabIndex = 4;  
zip.tabIndex = 5;  
email.tabIndex = 6;  
phone.tabIndex = 7;  
help.tabIndex = 8;

function validate (address) {  
/_if (address.length\>=7) {  
if (address.indexOf("@")\>0) {  
if ((address.indexOf("@")+2)\<address.lastIndexOf(".")) {  
if (address.lastIndexOf(".")\<(address.length-2)) {  
return (true);  
}  
}  
}  
}_/  
return (true);  
}

function formcheck () {  
//if ( (email.indexOf("@") \>0) ){// && email.indexOf(".") \> email.indexOf("@")+1 ) {  
//if ( (email == null) || (email.length\<1) || (name1 == null) || (name1.length\<1) || (name2 == null) || (name2.length\<1) || (address == null) || (address.length\<1) && (city == null) ||(city.length\<1) || (zip == null) || (zip.length\<1) || (phone == null) || (phone.length\<1) ){  
if ( (email == null) || (email.length\<1) || (name1 == null) || (name1.length\<1) || (name2 == null) || (name2.length\<1) ){ //only name help and email is mandatory  
sta= “Please fill in the fields”;  
}else if (!validate(email))  
{  
sta = “Email not valid”;  
}else{  
sta=“ok”;  
state1 = cb\_state.text;  
jenisphone = cb\_phone.text;

```
hear="";
if (h1.selected==true){
	hear += " Referral ";
	};
if (h2.selected==true){
	hear += " Advertising ";
	};
if (h3.selected==true){
	hear += " Online ";
	};
if (h4.selected==true){
	hear += " Neighborhood Sign ";
	};

villa ="";
if (cek1.selected==true){
	villa += " Roofing ";
	};
if (cek2.selected==true){
	villa += " Siding ";
	};
if (cek3.selected==true){
	villa += " Fascia and Soffit ";
	};
if (cek4.selected==true){
	villa += " Vinyl Replacement Windows ";
	};
if (cek5.selected==true){
	villa += " Seamless Gutters ";
	};
if (cek6.selected==true){
	villa += " Retail Estimate ";
	};
if (cek7.selected==true){
	villa += " Storm Damage ";
	};
if (cek8.selected==true){
	villa += " Employment Ops ";
	};
	
loadVariables("mailer.php", this, "POST");
gotoAndStop("wait");
}

```

}
