Hey guys, new to the site. Going to see if I can get some solid answers here as I haven’t found anything to be quite what I need just yet and I’ve been searching for days now. It’s really starting to eat up some precious development time.
Laymen: I am looking for/trying to write my own contact form that will send an admin an email. Got that part. However, I also, need it to send two text messages, 15 minutes apart, to a business owner/business manager alerting them they have a lead. Again I am newer to php but it should be possible and fairly easy. I feel as though all my failed attempts to make the form complete both have failed because I was not linking up the variables up correctly or possibly some other ignorance issue.
I feel like if I write another if clause after this php code and send out the txt there it should work.
[php]<?php
if(isset($_POST[‘email’])) {
$email_to = "[email protected]";
$email_subject = "Inquiry from DuncansDotInfo";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first']) ||
!isset($_POST['last']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['industry']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first']; // required
$last_name = $_POST['last']; // required
$phone = $_POST['phone']; // required
$industry = $_POST['industry']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= ‘The Email Address you entered does not appear to be valid.
’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$first_name)) {
$error_message .= ‘The First Name you entered does not appear to be valid.
’;
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= ‘The Last Name you entered does not appear to be valid.
’;
}
if(strlen($comments) < 2) {
$error_message .= ‘The Comments you entered do not appear to be valid.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Industry: ".clean_string($industry)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header(“Location: thanks.php”);
?>
<form method="post" action="form_send.php">
<p>First Name:<input type="text" name="first" placeholder="Johnny"></input><br />
Last Name:<input type="text" name="last" placeholder="Appleseed"></input><br />
Phone:<input type="text" name="phone" placeholder="224-858-9855"></input><br />
Industry:<input type="text" name="industry" placeholder="Reality"></input><br />
E-Mail:<input type="email" name="email" placeholder="[email protected]"></input><br />
How much are you inclined to invest monthly:<select><option value="159">$159</option> or <option value="399">$399</option></select><br />
Message:<textarea name="comments" placeholder="Question or Business Information"></textarea><br />
<input type="submit" value="FREE CONSULTATION AND FREE MONTH"></input><br />
<img src="" />Try our Facebook™ Messenger<br />
<em>Response time >2 Minutes!</em>
</p>
</form>
I am thinking I have everything labeled correctly, but again I am not sure. Any advise would be beneficial.
Thanks in advance,
JaDuncan