Php 无法将表单数据发送到电子邮件

Php 无法将表单数据发送到电子邮件,php,html,Php,Html,大家好,我已经设计了一个网页,其中有在线注册表格,我希望填写的表格数据被发送到电子邮件id,因为我使用了下面的代码 $to = 'example@example.com'; $subject = 'I need to show html'; $from ='from@from.com'; $body = '<p style=color:red;>This text should be red</p>'; ini_set("sendmail_from", $fr

大家好,我已经设计了一个网页,其中有在线注册表格,我希望填写的表格数据被发送到电子邮件id,因为我使用了下面的代码

$to = 'example@example.com';

$subject = 'I need to show html'; 

$from ='from@from.com'; 

$body = '<p style=color:red;>This text should be red</p>';

ini_set("sendmail_from", $from);

$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
  $headers .= "Content-type: text/html\r\n"; 
if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }
我用免费的网络托管来测试这个,一切都很好,但提交的细节没有提到电子邮件id,我真的是个新手,有人能帮我吗

以下是表格代码:

这里是Submission.php代码


首先,问题是它是一封html电子邮件,所以请为它使用正确的标题,然后在html文件体中发送所需的表单数据

用这个测试,让我知道它是否工作

    $to = 'from@from.com';
    $subject = 'I need to show html'; 
    $from ='from@from.com'; 
    ini_set("sendmail_from", $from);
    $username=$_POST['name'];
    $mobilenum=$_POST['mobileno'];
    $cname=$_POST['cname'];
    $address=$_POST['address'];
    $postalcode=$_POST['postalcode'];
    $headers = "From: " .$from. "\r\n";
    $headers .= "Reply-To: ".$from. "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $body = '<p style=color:red;>This text should be red</p>';
    $body.='<label>User Name:</label>'.$username.'<br>';
    $body .= '<label>Mobile Num:</label>'.$mobilenum.'<br>';
    $body .= '<label>Company Name:</label>'.$cname.'<br>';
    $body .= '<label>Address:</label>'.$address.'<br>';
    $body .= '<label>Postalcode:</label>'.$postalcode.'<br>';

if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }

你为什么要使用.com.com两次?这是我错误输入的电子邮件ID号吗,在代码中它是正确的,我现在已经编辑过了,请删除。在首席信息官编辑完问题hi@sandepsk后,你能告诉我表格中的可用文件是什么吗?你没有将提交的详细信息发送到邮件,因此它不起作用,但我有大约5个字段,只有名字或用户名数据进入我的邮件id,其他人没有进入邮件,我使用了类似的连接方法,支持您有建议字段,像这样添加其他5个字段也$body.='suggestions:'.$\u POST['suggestions']。;如何得到正确的文本格式,我得到它与html标签它的形式,你的问题,然后我会检查我已经尝试了它的工作,但它没有正确的格式,我得到标签标签
<?php 
$submit=1;
if( !isset($_POST[$submit]) )
 {

 }
 else{
  header('Location:index.php');
   exit;
 }
 ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Thank You For Registration</title>
</head>

<body>
<h4>Registration Sucessfull</h4><br/>
<a href="index.php">Go To Registration Page</a>
</body>
</html>
    $to = 'from@from.com';
    $subject = 'I need to show html'; 
    $from ='from@from.com'; 
    ini_set("sendmail_from", $from);
    $username=$_POST['name'];
    $mobilenum=$_POST['mobileno'];
    $cname=$_POST['cname'];
    $address=$_POST['address'];
    $postalcode=$_POST['postalcode'];
    $headers = "From: " .$from. "\r\n";
    $headers .= "Reply-To: ".$from. "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $body = '<p style=color:red;>This text should be red</p>';
    $body.='<label>User Name:</label>'.$username.'<br>';
    $body .= '<label>Mobile Num:</label>'.$mobilenum.'<br>';
    $body .= '<label>Company Name:</label>'.$cname.'<br>';
    $body .= '<label>Address:</label>'.$address.'<br>';
    $body .= '<label>Postalcode:</label>'.$postalcode.'<br>';

if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }