Jump to content

Recommended Posts

Hey guys, I have a very short script that I am using to to just pull info from an email form. I am fluent in html/css but the php here that is causing me problems. Could I trouble anyone to take a quick look for errors? The script was taken from an online source and slightly altered.

 

<?php
if(isset($_POST['email'])) {

$email_to = "[email protected]";
$email_subject = "Inquiry";


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['name']) ||
	!isset($_POST['email']) ||
	!isset($_POST['website']) ||
	!isset($_POST['project'])) {
	died('We are sorry, but there appears to be a problem with the form you submitted.');		
}

$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['website']; // not required
$comments = $_POST['project']; // required

$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
  	$error_message .= 'The email address you entered does not appear to be valid.<br />';
  }
$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$name)) {
  	$error_message .= 'The name you entered does not appear to be valid.<br />';
  }
  if(strlen($project) < 2) {
  	$error_message .= 'The project description you entered do not appear to be valid.<br />';
  }
  $string_exp = "^[0-9 .-]+$";
  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 .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Website: ".clean_string($website)."\n";
$email_message .= "Project: ".clean_string($project)."\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);  
?>

Thank you for contacting us. We will be get back to you very soon.

<?
}
?>

 

The form itself is set up fine with method="post' and action="send_form_email.php", but I am doing something wrong here. Any suggestions? Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/206431-form-to-email-script-issues/
Share on other sites

A) Like mrMarcus just wrote, you did not provide any help as to what it did do, and

 

B) You might want to read the following thread because it appears to be the same basic code - http://www.phpfreaks.com/forums/index.php/topic,302757.0.html

Wow, I feel like kind of an idiot - not actually writing the problem down. Winner here. Anyhow the error it says is:

 

"We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.

 

We are sorry, but there appears to be a problem with the form you submitted.

 

Please go back and fix these errors."

 

Now, I must tell you - I literally know near nothing of php or how the language operates. So I don't know if or how to tell the script is running, but I ran the code in its original state (taken from http://www.freecontactform.com/email_form.php), and it sent through just fine. I am really clueless here on what is going wrong in my version. However, I am sure I can understand what is what just by using common sense if someone were to point out an error they see. To see it run live, you can use the Contact Us form at www.omni-flux.com/progress/. From there the form action just uses send_form_email.php which is the code from my OP. I modified the script to use 4 items with different names for each "event" (terminology?) or text fields instead of the 5 originally written in there. That may be a reason it's not working. Is this enough info?

 

Thank you for your replies so far!

That it prints out something means that the <? tag is not a problem (you should change it to <?php anyway.)

 

The error message it does print is 'We are sorry, but there appears to be a problem with the form you submitted.' That implies that not all of your form field are named as indicated in the php code, because they would be set, even if empty.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.