HTTP POST表单处理与PHP

问题描述:

我这里有一个表格:http://www.testing-joestanford.co.uk/example/HTTP POST表单处理与PHP

我希望它提交给http://www.testing-joestanford.co.uk/ 或其他地方,这并不重要,我。

我需要什么URL才能处理表单并向我发送数据电子邮件(以最基本的形式),而无需重定向到该页面(如果可能)。

难道是一些PHP如:

<?php 

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

function SendEmail($mailto, $subject, $title) 
{ 
    $header = "From: [email protected]"."\r\n"; 
    $header .= "Reply-To: [email protected]"."\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); 
} 

?> 

还是我吠叫完全错了?

任何帮助非常感谢,谢谢。

+0

我不确定我是否理解这个问题,您是否设置了表单的“action =”“'?否则,考虑'header('Location:');' – Epodax

+0

是的,表单被设置为POST到http://www.testing-joestanford.co.uk/。我只是努力让它给我发送提交的数据。谢谢。 –

+0

您是否收到任何错误/警告(确保显示错误,请参阅http://*.com/questions/1053424/how-do-i-get-php-errors-to-display)? –

你的形式@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> 

确保从这个URL处理表单数据。 你的服务器端的PHP脚本来处理数据

@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: [email protected]"."\r\n"; 
     $header .= "Reply-To: [email protected]"."\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); 
    } 


} 

注:如果你不想从表单页面重定向,看看AJAX表单提交(仅限某些jQuery的除了HTML表单页面)。

+0

感谢您的支持,但我在提交数据时遇到了500个服务器错误。 –