Created
April 1, 2017 08:53
-
-
Save codehakase/6dd6ed2c8a7875dc15fd36f93b454de6 to your computer and use it in GitHub Desktop.
Mail script solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if (isset($_POST)) { | |
| $email = $_POST['email']; | |
| $values = ['Name','Address','Phone','Email','BusinessType','Budget']; | |
| $required = ['Name','Address','Phone','Email','BusinessType','Budget']; | |
| $your_email = "[email protected]"; | |
| $email_subject = "New Message: ".$_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 'Message sent!'; | |
| break; // stops loop at this point | |
| return true; | |
| } | |
| else { | |
| echo 'ERROR!'; | |
| return; | |
| } | |
| } // end of loop | |
| } else { | |
| // catch exceptions here | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment