0

I am trying to create a simple PHP email form that I can embed into my website. I have two problems, the syntax appears to be wrong past href=\"\"> and I am not sure why. The rest of the text appears in the browser past that href=\"\"> section. If I use this form, won't it be easier to keep users from seeing my email in this PHP form? Be advised, I am new to PHP

<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
    { 
    ?> 
<form  action="" method="POST" enctype="multipart/form-data"> 
<input type="hidden" name="action" value="submit">
Your email:<br> 
<input name="email" type="text" value="" size="30"/><br> 
Your message:<br> 
<textarea name="message" rows="7" cols="30"></textarea><br> 
<input type="submit" value="Send email"/> 
</form> 
<?php 
}  
else                /* send the submitted data */ 
{ 
$email=$_REQUEST['email']; 
$message=$_REQUEST['message']; 
if (($name=="")||($email=="")||($message=="")) 
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{         
    $from="From: $name<$email>\r\nReturn-path: $email"; 
    $subject="Message sent using your contact form"; 
    mail("[email protected]", $subject, $message, $from); 
    echo "Email sent!"; 
    } 
}   
?> 

See anything wrong?

7
  • What actually happens when you submit the form? Is an email sent, do you get a white screen/php error message? If the code works as is, this may be better suited for codereview.stackexchange.com Commented Aug 5, 2014 at 18:40
  • 1
    Try this, echo "All fields are required, please fill <a href=''>the form</a> again."; Commented Aug 5, 2014 at 18:42
  • Where exactly is the name input????? Commented Aug 5, 2014 at 18:44
  • Why would you want an empty href ? Commented Aug 5, 2014 at 18:47
  • 1
    @thebluedog And what did you see ? Commented Aug 5, 2014 at 18:50

1 Answer 1

1

You are checking for $name and it doesn't exist. This will get you working but you should check if the $_REQUEST exists before you define it. Always write code with error reporting on.

<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
    { 
    ?> 
<form  action="" method="POST" enctype="multipart/form-data"> 
<input type="hidden" name="action" value="submit">
Your email:<br> 
<input name="email" type="text" value="" size="30"/><br> 
Your message:<br> 
<textarea name="message" rows="7" cols="30"></textarea><br> 
<input type="submit" value="Send email"/> 
</form> 
<?php 
}  
else                /* send the submitted data */ 
{ 
$email=$_REQUEST['email']; 
$message=$_REQUEST['message']; 
if (($email=="")||($message=="")) 
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{         
    $from="From: $name<$email>\r\nReturn-path: $email"; 
    $subject="Message sent using your contact form"; 
    mail("[email protected]", $subject, $message, $from); 
    echo "Email sent!"; 
    } 
}   
?> 
Sign up to request clarification or add additional context in comments.

3 Comments

Nice mod, but I hope he didn't want the name... Never mind the 'other' problem(s).
Agreed lol. IT looks like it use to be an option then was removed so I assumed it was not needed by looking at the form. He can figure that out tho
I like your reasoning!