Jump to content

PHP Mailer Contact Form Help


reubikcube2013
Go to solution Solved by Bottyz,

Recommended Posts

I have the following html code for a form;

<form action="email.php" method ="POST" >
      <label>Name</label><br>
      <input type="text" value="" class="form" name ="name"><br>
      
      <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;

<html>
<body>
Thankyou <?php echo $_POST["name"]. ","; ?> <br>
<?php echo $_POST["email"]; ?> Will be contacted soon.
<?php
$to = "example@example.com";
$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")?>

</body>
</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.  shocked.gif cry.gif

Kind Regards,

R.

Link to comment
Share on other sites

Just a thought, have you added 

<?php session_start(); ?>

at the beginning of your email.php?

 

You'll also want to keep the user on that page for a few seconds before redirecting to index.html as you'll want them to see the notice you've written, so add

header ("refresh: 5; url=index.html");

 instead of 

header("Location: index.html");
Edited by Bottyz
Link to comment
Share on other sites

 

Just a thought, have you added 

session_start();

at the beginning of your email.php?

 

You'll also want to keep the user on that page for a few seconds before redirecting to index.html as you'll want them to see the notice you've written, so add header

header ("refresh: 5; url=index.html");

 instead of 

header("Location: index.html");

Thanks for the response changed the code to this;

<html>
<body>
<?php session_start();?>
Thankyou <?php echo $_POST["name"]. ","; ?> <br>
<?php echo $_POST["email"]; ?> Will be contacted soon.
<?php
$to = "example@example.com";
$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)


( "refresh:5;url=index.html" );?>


</body>
</html>

and the exact same thing has happened- a static white page is displayed. 

Link to comment
Share on other sites

  • Solution

For a start the session_start needs to go above everything else.

The blank page would normally mean you've missing a semi colon or similar (best to check error logs for specifics) my guess would be the missing semi-colon from:

mail($to, $subject, $message, $headers)

should be:

mail($to, $subject, $message, $headers);
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.