0

I've looked through a lot of posts on a lot of different websites, including this one and still can't figure out whats going on. First of all I'm not getting an email to my desired email in put in the PHP file. My redirect is also not going the html page I designated, instead it goes to the PHP file, which is just a blank page when viewed.

HTML

<form action="result.php" method="post" enctype="text/plain" name="form1"> <table width="500" border="0" align="center" cellspacing="0"> <tr> <td>Name:</td> <td><input name="name" type="text" size="30" maxlength="30"></td> </tr> <tr> <td>Email:</td> <td><input name="email" type="text" size="30" maxlength="50" placeholder="[email protected]"></td> </tr> <tr> <td>Phone:</td> <td><input name="phone" type="text" size="30" maxlength="20"></td> </tr> <tr> <td>Inquiry type:</td> <td><select name="type"> <option value="1" selected>Residential Inquiry</option> <option value="2">Small Business Inquiry</option> <option value="3">Web Design Inquiry</option> <option value="4">Existing Client Inquiry</option> </select></td> </tr> <tr> <td>Message:</td> <td><textarea name="message" cols="45" rows="5"></textarea></td> </tr> <tr> <td>&nbsp;</td> <td><input name="submit" type="submit" value="Submit" /> <input name="reset" type="reset" value="Reset" /></td> </tr> </table> </form> 

PHP

<?php $name = $_POST['name']; $visitor_email = $_POST['email']; $phone = $_POST['phone']; $subject = $_POST['type']; $message = $_POST['message']; if(IsInjected($visitor_email)) { echo "Bad email value!"; exit; } $email_from = '[email protected]';//<== update the email address $email_subject = "$subject"; $email_body = "$message" + "phone"; $to = "[email protected]"; //<== update the email address $headers = "From: $email_from \r\n"; $headers = "Reply-To: $visitor_email \r\n"; //Send the email! mail($to,$email_subject,$email_body,$headers); //done. redirect to thank-you page. header('Location: http://www.example.com/example.html'); // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> 
1
  • PHP doesn't handle text/plain. Commented Feb 11, 2014 at 15:57

3 Answers 3

2

Remove this

 enctype="text/plain" <form action="result.php" method="post" enctype="text/plain" name="form1"> 

from the form tag and add this

<form action="result.php" method="post" name="form1"> 
Sign up to request clarification or add additional context in comments.

5 Comments

I'm still getting the same errors, no email is coming in and it redirects to the blank php page.
Thats was one part of the issue you need to turn on error on result.php and check for errors.
I got the email to work exactly how I wanted. The redirect is the last thing working incorrectly.
remove all the blank spaces from the top of your result.php
Thank you, I got it to work. For some reason I had some html above the <?php and it was messing with it. Not sure where I read to put that in there.
1

You have set the form encoding to "Human readable debug mode"

 enctype="text/plain" 

See the specification:

Payloads using the text/plain format are intended to be human readable. They are not reliably interpretable by computer, as the format is ambiguous (for example, there is no way to distinguish a literal newline in a value from the newline at the end of the value).

Don't do that. Take the attribute out.

2 Comments

I deleted that part of the form code. I still receive no email and hitting submit still redirects to the blank result.php page instead of my html page I want it to. I made sure it was the right email multiple times as well.
Look in your server logs. Does PHP report any errors?
0

Might need to concatenate your header information:

$headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; 

1 Comment

I ended up changing it to this $headers = "Reply-To: " . $visitor_email . "\r\n"; and deleting the other one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.