Php代码的形式不工作.代码声明在这里



表格的代码为:-

  <form action="mail.php">
  <input class="input-text" type="text" name="name" value="Your Name *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
  <input class="input-text" type="text" name="email" value="Your E-mail *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
  <textarea class="input-text text-area" name="message" cols="0" rows="0" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">Your Message *</textarea>
  <input class="input-btn" type="submit" value="send message">
  </form>

我已经托管的网页,但形式不工作。我还需要做些什么才能使它发挥作用呢?

下面是PHP代码:-
<html>
<body>
<?php 
$errors = '';
$myemail = 'xyz@abc.com.com';
if(empty($_POST['name'])  ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match("/ ^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "n Error: Invalid email address";
}
if( empty($errors))
{
$to = '$myemail';
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
    " Here are the details:n Name: $name n ".
    "Email: $email_addressn Message n $message";
$headers = "From: $myemailn";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'indes' page
header('Location: index.html');
}
?>

我已经完成了php部分并将其上传到网站,但仍然没有从联系表单发送任何邮件。也就是说,它根本没有响应。我现在能得到帮助吗?

您需要有一种在提交时收集它的方法。浏览一下这个网站,会为你提供更多的信息。

本质上,你需要使用PHP之类的东西来收集和处理信息,要么将其存储到数据库中,要么通过电子邮件发送给自己。

HTML,PHP联系人表单

mail.php

<?php
   $name    = $_POST['name'];
   $email   = $_POST['email'];
   $message = $_POST['message'];
   $to      = 'nobody@example.com';
   $subject = 'the subject';
   $headers = 'From: webmaster@example.com' . "rn" .
              'Reply-To: webmaster@example.com' . "rn" .
              'X-Mailer: PHP/' . phpversion();
   mail($to, $subject, $message, $headers);
?> 
   // Either insert into database or email to yourself.  You would want to look at sanitizing the inputs a bit and checking for valid email addresses. 
PHP邮件()

相关内容

最新更新