PHP Mailer Form

I have the following html code for a form;

Name

  <label>Email</label><br>
  <input type="text" value="" class="form" name ="email"><br>
  
  <label>Message</label><br>
    <textarea rows ="3" class ="form" name ="message"></textarea>
    
    <label></label><br>
    <input type="submit" value="submit">
    </form>

the form has the action of a file called email.php-this file is meant to send the users details to an email address using the mail function. It contains the following;

Thankyou <?php echo $_POST["name"]. ","; ?>
<?php echo $_POST["email"]; ?> Will be contacted soon. <?php $to = "[email protected]"; $name = $_POST["name"]; $email =$_POST["email"]; $message = $_POST["message"]; $subject="Web Design"; $headers = 'From:'. $email . "\r\n" . 'Reply-To:'. $name . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers)

header(“Location: index.html”)?>

I have tried the code with a working email address however none of it seems to work- what happens is when the submit button is clicked the user is redirected a plain white page ("/email.php"). Looking for help urgently. :o :'(

Kind Regards,

R.

Well, Reubikcube, your code is basically badly formed. It has no safeguards to protect your server at all and
no error checking either. But, here is one general way that might fix up your errors…

email.php :
[php]

<?php $to = "[email protected]"; $name = $_POST["name"]; $email =$_POST["email"]; $message = $_POST["message"]; $subject="Web Design"; $headers = 'From:'. $email . "\r\n" . 'Reply-To:'. $name . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (mail($to, $subject, $message, $headers)) { echo "Thankyou " . $_POST["name"] . ",
" . $_POST["email"] . "Will be contacted soon."; } else { echo "There was an error sending your email!"; } ?> [/php] That is just the basic idea, no way close to a full email code. Just something to get you started! You should add in validation code to make sure they are not inserting code into the message, etc... Good luck!

I would suggest using PHPMailer or another 3rd Party Mailer, it’ll save you some headaches not having to worry too much about security. However, you will still need validation as already mention. This is just a suggestion.

Sponsor our Newsletter | Privacy Policy | Terms of Service