Jump to content

Contact Form Not Recieved


txapache

Recommended Posts

Second Set of EYes, Hopefully this is it.  I put in questions to hosting company with no response yet and now am asking yall (yes Texas),  Please glanceat the form and processor and tell me if you see anything wrong.  I test the contact form and get the Thank you message but never receive the email.

 

Form:

<form action="email_controller.php" method="post" enctype="text/plain" style="margin-top: 25px; margin-left: 20px;">
<table>
<tr>
	<td>Name:</td>
	<td><input type="text" name="name" size="40" maxlength="100" ONCHANGE="var pattern=/[0-9]/; if(pattern.test(this.value))alert('Please enter a valid name')"></td>
</tr><tr>
	<td>Company Name:</td>
	<td><input type="text" name="company" size="40" maxlength="100"></td>
</tr><tr>
	<td>Website Address:</td>
	<td><input type="text" name="website" size="40" maxlength="100"></td>
</tr><tr>
	<td>Email Address:</td>
	<td><input type="text" name="email" size="40" maxlength="100" ONCHANGE="var pattern=/[\s]/; if(pattern.test(this.value))alert('Please enter a valid email address')"></td>
</tr><tr>
	<td>Phone Number:</td>
	<td><input type="text" name="phonenumber" size="15" maxlength="15"></td>
</tr><tr>
	<td colspan="2">Comments:</td>
</tr><tr>
	<td colspan="2" background="#d2b48c"><textarea name="comments" cols="50" rows="10"></textarea></td>
</table>
<input type="image" name="image" value="Submit" src="images/submitbutton.png" width="100" height="35" border="0" alt="Submit!"/>
<input type="hidden" name="subject" value="Submission"/>
<input type="hidden" name="redirect" value="index.php"/>
<input type="hidden" name="form_order" value="alpha"/>
<input type="hidden" name="form_delivery" value="hourly"/>
<input type="hidden" name="form_format" value="html"/>

</form>

 

Processor:

<?php 
ini_set("display_errors", "1");
error_reporting(-1);

if(isset($_POST['email'])) { 
      
    // EDIT THE 2 LINES BELOW AS REQUIRED 
    $email_to = 'me@mysite.com'; 
    $email_subject = 'Contact Us'; 
    $email_from = ($_POST['name'];  
      
    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['company']) ||
	!isset($_POST['website']) ||
	!isset($_POST['email']) || 
        !isset($_POST['phonenumber']) || 
        !isset($_POST['comments'])) { 
        died('We are sorry, but there appears to be a problem with the form you submitted.');        
    } 
      
    $firstname = $_POST['firstname']; // required 
    $company = $_POST['company']; //not required
$website = $_POST['website']; // not required
$email = $_POST['email']; // required 
    $phonenumber = $_POST['phonenumber']; // not required 
    $comments = $_POST['comments']; // required 
      
    $error_message = ""; 
    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; 
  if(!eregi($email_exp,$email)) { 
    $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 First Name you entered does not appear to be valid.<br />'; 
  } 
  if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
  } 
  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 .= "Company: ".clean_string($company)."\n";
$email_message .= "Website: ".clean_string($website)."\n";
$email_message .= "Email: ".clean_string($email)."\n"; 
    $email_message .= "Telephone: ".clean_string($phonenumber)."\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: thankyou.html");

}

?> 

Link to comment
Share on other sites

I don't see anything that is obviously wrong with the code.  Remove the @ symbol before the mail call while you're debugging this, as that would suppress any errors.  I'm assuming that what WebStyles pointed out is just something you changed before posting, and that you are using an actual email address.  It is possible that your email is being sent, but that the email is in your spam folder.

Link to comment
Share on other sites

Yes me@mysite was changed, on line 10 I added ")" to close the bracket and took at the @ symbol.  At first I was just getting a white page but with those changes it now send me to the thankyou page as if the form was submitted, but I do not get the form in the email.  I have checked the spam/junk folder also and nothing.  No error messages displayed on page or error log.

Link to comment
Share on other sites

// 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: thankyou.html");

 

The value you supply in the "From:" header needs to be a valid email address. It also needs to be an email address that belongs to the server that is sending the mail. Some servers will NOT send mail if the from is not an address it owns (since that indicates you are trying to fake a message), and some servers will NOT accept mail if the from address does not belong to the server sending it (again, it appears to be an attempt to impersonate someone). You have set $email_from to the NAME entered by the user, which is likely not a valid email address.

 

You are also setting the "Reply-To:" header to the user's name. This should be a valid email address as well. You should set this to the email address that the user entered.

 

Your $email_to variable should be set (as it originally was) to the person you want to receive the message.

Link to comment
Share on other sites

Ok new information, tried the test script but error need from.  On to my test, I had the thank you html at the bottom of the email_controller.php and so when I submit form I would get the thankyou screen.  I place the following code in the html section:

<pre>
<strong>DEBUG:</strong>
<?php
print_r($_POST);
?>
</pre>

and would get DEBUG array ().

 

So nothing was being posted.  I took the HTML part of the email_controller and placed it on its own page changed the header section to

header('Location: thankyou.php');

Processed the form again and got a blank email_controller.php page.  So for some reason when the form is filled out, none of the information is being ppicked up by the controller.  Not sure why I figured the following script would grab the info

$firstname = $_POST['firstname']; // required 
    $company = $_POST['company']; //not required
$website = $_POST['website']; // not required
$email = $_POST['email']; // required 
    $phonenumber = $_POST['phonenumber']; // not required 
    $comments = $_POST['comments']; // required 
    

 

Link to comment
Share on other sites

Have you done the simple test that WebStyles provided?  This is the first thing you need to do.  Some of the things that you say you are trying are pointless and irrelevant.  One small incorrect detail will prevent the outbound email from being delivered.  There are a lot of potential problems, and we need to eliminate them systematically, but we can't do that if you don't follow the instructions and advice of the people who are trying to help you debug this.

Link to comment
Share on other sites

You are running this under XAMPP!!!!!

 

I wish we had known this earlier.

 

I don't use xampp but what I've read it apparently comes with an email server named Mercury SMTP.

 

I'm not really sure it's worth trying to get something functional setup when you are not going to be using that as your productions server, however, here's a detailed how-to that describes how you might accomplish using it:  http://www.danieltmurphy.com/setting-up-mercury-smtp/

 

There are intractible problems here like again the fact that email you send from this sort of setup will inevitably be seen as spam by any normal email provider you're using for testing, however, it may be enough in this case to give you verification you need while you test your code.

 

For windows, settings in the php.ini that tell php where it can send email, need to be changed, so that php has a mailserver that can talk SMTP protocol, and will accept and forward email for you.  So the other alternative is to set it to forward email to your local ISP that looks like it came from your normal workstation.  Whether or not that is a feasible alternative pretty much depends on your ISP, and whether or not you can figure out what you need to do for the relevant settings in the php.ini.  This is described a bit in the manual: http://us2.php.net/manual/en/mail.configuration.php#ini.smtp

 

 

Link to comment
Share on other sites

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.