0

I have a form here: http://www.testing-joestanford.co.uk/example/

I want it to submit to http://www.testing-joestanford.co.uk/ or elsewhere, it doesn't matter to me.

What do i need on that URL to process the form and send me an email of the data (in it's most basic form) without redirecting to that page (if possible).

Would it be some PHP such as:

<?php 

// create mail message to merchant
$subject = "Form data";
$title = "Example title.";
SendEmail("example@domain.co.uk", $subject, $title, false);

function SendEmail($mailto, $subject, $title)
{
   $header  = "From: example@domain.co.uk"."\r\n"; 
   $header .= "Reply-To: example@domain.co.uk"."\r\n"; 
   $header .= "MIME-Version: 1.0"."\r\n"; 
   $header .= "Content-Type: text/plain; charset=utf-8"."\r\n"; 
   $header .= "Content-Transfer-Encoding: 8bit"."\r\n"; 
   $header .= "X-Mailer: PHP v".phpversion(); 

   $message .= "Name: PS".$name."\r\n";


   mail($mailto, $subject, stripslashes($message), $header); 
}

?>

Or am i barking up the completely wrong tree?

Any help is hugely appreciated, thank you.

  • I'm not sure I understand the question, have you set the form's `action=""` ?? Otherwise consider `header('Location:');` – Epodax Mar 01 '16 at 11:00
  • yes, the form is set to POST to http://www.testing-joestanford.co.uk/. I am just struggling to get it to email me the submitted data. Thanks. – Joe Stanford Mar 01 '16 at 11:07
  • Do you get any errors / warnings (make sure errors are shown, see http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)? – Tobias Xy Mar 01 '16 at 11:19

1 Answers1

0

Your form @ http://www.testing-joestanford.co.uk/example/

<html>
<body>

<form action="http://www.testing-joestanford.co.uk/" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

Make Sure to handle the form data from this url. Your server side PHP script to handle the data

@ http://www.testing-joestanford.co.uk/index.php

<?php
// form handler
if( $_POST['name'] && $_POST['email'] )) {

    $name = $_POST['name'];
    $email = $_POST['email'];

    // create mail message to merchant
    $subject = "Form data";
    $title = "Example title.";
    SendEmail($email, $subject, $title, false);

    function SendEmail($mailto, $subject, $title)
    {
        $header  = "From: example@domain.co.uk"."\r\n"; 
        $header .= "Reply-To: example@domain.co.uk"."\r\n"; 
        $header .= "MIME-Version: 1.0"."\r\n"; 
        $header .= "Content-Type: text/plain; charset=utf-8"."\r\n"; 
        $header .= "Content-Transfer-Encoding: 8bit"."\r\n"; 
        $header .= "X-Mailer: PHP v".phpversion(); 

        $message .= "Name: PS".$name."\r\n";


        mail($mailto, $subject, stripslashes($message), $header); 
    }


}

NOTE : If you don't want to redirect from the form page, look into AJAX form submission (Only some Jquery addition to the HTML form page).

Sharan Mohandas
  • 861
  • 1
  • 9
  • 25