Skip to content

Instantly share code, notes, and snippets.

@codehakase
Created April 1, 2017 08:53
Show Gist options
  • Select an option

  • Save codehakase/6dd6ed2c8a7875dc15fd36f93b454de6 to your computer and use it in GitHub Desktop.

Select an option

Save codehakase/6dd6ed2c8a7875dc15fd36f93b454de6 to your computer and use it in GitHub Desktop.
Mail script solution
<?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