Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP,无法发送电子邮件_Php_Forms_Validation - Fatal编程技术网

PHP,无法发送电子邮件

PHP,无法发送电子邮件,php,forms,validation,Php,Forms,Validation,我想在我的电脑上有一张需要*全名、*电子邮件地址、*主题和*信息的联系表。我按照一个教程开发了我的表单,但由于某些原因,它没有发送我的测试消息 我没有足够的PHP经验来找出我做错了什么,所以我希望能得到关于如何解决这个问题的建议。欢迎提出所有问题、建议和可能的解决方案。谢谢 联系方式: 代码: 联系方式HTML: 代码: 你的信息* 发送消息 表单的操作未设置为任何值。您需要将它指向发送电子邮件的脚本 即: 设置正确的操作,然后尝试该操作。。 如果它仍然无法工作,请使用curl实用程序测试

我想在我的电脑上有一张需要*全名、*电子邮件地址、*主题和*信息的联系表。我按照一个教程开发了我的表单,但由于某些原因,它没有发送我的测试消息

我没有足够的PHP经验来找出我做错了什么,所以我希望能得到关于如何解决这个问题的建议。欢迎提出所有问题、建议和可能的解决方案。谢谢

联系方式: 代码:


联系方式HTML: 代码:


你的信息*
发送消息

表单的操作未设置为任何值。您需要将它指向发送电子邮件的脚本

即:


设置正确的操作,然后尝试该操作。。 如果它仍然无法工作,请使用curl实用程序测试它,看看您的脚本是否正常。。 我看到的另一个错误是,您的文本区域表单名称是msg,而在服务器上,您希望您的post请求包含消息。那不行。。
如果您仍然面临这个问题,那么我们需要进一步调试:)

首先您需要为某些脚本设置操作,这些脚本将处理同一文件的
$\u POST
输入(
contactform.php
)或
$\u服务器['php\u SELF']


其次,您应该通过输入
type=submit
not按钮发送数据。

从邮件中删除“@”。。。不要用“hand”验证电子邮件地址@Dagon:我从评论行猜测OP是从某处得到的,所以它可能在某种程度上起作用。不管它是否有效……我同意@Dagon的观点。var_dump($_POST)查看表单是否到达控制器。名称验证也错误。只是抢占了OP的下一篇文章。从使用的json_encode()判断,我认为这里涉及AJAX。哦,只要使用JS,就应该在客户端验证表单。如果您还没有使用jQuery,那么就使用它,然后使用这个插件。事实并非如此。如果您查看脚本,它将在同一url上发布到自身。action=''是一种有效的方法(我不建议这样做)。@MatthewBlancarte:假设表单是由同一个脚本输出的,当然。然而,从脚本看起来“开箱即用”的事实来看,它可能没问题。PHP表单脚本仍然无法工作。我回到了我下载脚本的网站,但它在那里根本不起作用!!!看来我得写一个PHP表单脚本了。。唉。有人能给我介绍一个关于创建带有验证的php表单脚本的好教程吗?出于好奇,php表单不一定要在.php文件中,也可以在.html文件中吗?为action属性保留一个空字符串是将表单发布到自身的有效方法$_服务器['PHP_SELF']是不必要的。
<?php 

// EDIT THE FOLLOWING LINE BELOW AS REQUIRED

$send_email_to = "jb@me.com";

function send_email($name,$email,$email_subject,$email_message)
{
  global $send_email_to;  

  $headers = "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  $headers .= "From: ".$email. "\r\n";

  $message = "<strong>Email = </strong>".$email."<br>";
  $message .= "<strong>Name = </strong>".$name."<br>";
  $message .= "<strong>Message = </strong>".$email_message."<br>";
  @mail($send_email_to, $email_subject, $message,$headers);
  return true;
}

function validate($name,$email,$message,$subject)
{
  $return_array = array();
  $return_array['success'] = '1';
  $return_array['name_msg'] = '';
  $return_array['email_msg'] = '';
  $return_array['message_msg'] = '';
  $return_array['subject'] = '';

 if($email == '')
  {
    $return_array['success'] = '0';
    $return_array['email_msg'] = 'email is required';
  }
  else
  {
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email)) {
      $return_array['success'] = '0';
      $return_array['email_msg'] = 'enter valid email.';  
    }
  }

  if($name == '')
  {
    $return_array['success'] = '0';
    $return_array['name_msg'] = 'name is required';
  }
  else
  {
     $string_exp = "/^[A-Za-z .'-]+$/";
    if (!preg_match($string_exp, $name)) {
      $return_array['success'] = '0';
     $return_array['name_msg'] = 'enter valid name.';
    }
  }


  if($subject == '')
  {
    $return_array['success'] = '0';
    $return_array['subject_msg'] = 'subject is required';
  }

  if($message == '')
  {
    $return_array['success'] = '0';
    $return_array['message_msg'] = 'message is required';
  }
  else
  {
    if (strlen($message) < 2) {
      $return_array['success'] = '0';
      $return_array['message_msg'] = 'enter valid message.';
    }
  }
  return $return_array;
}

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

$return_array = validate($name,$email,$message,$subject);
if($return_array['success'] == '1')
{
  send_email($name,$email,$subject,$message);
}

header('Content-type: text/json');
echo json_encode($return_array);
die();

?>
<fieldset id="contact_form">
          <div id="msgs"> </div>
          <form id="cform" name="cform" method="post" action="">
            <input type="text" id="name" name="name" value="Full Name*" onfocus="if(this.value == 'Full Name*') this.value = ''"
                            onblur="if(this.value == '') this.value = 'Full Name*'" />
            <input type="text" id="email" name="email" value="Email Address*" onfocus="if(this.value == 'Email Address*') this.value = ''"
                            onblur="if(this.value == '') this.value = 'Email Address*'" />
            <input type="text" id="subject" name="subject" value="Subject*" onfocus="if(this.value == 'Subject*') this.value = ''"
                            onblur="if(this.value == '') this.value = 'Subject*'" />
            <textarea id="msg" name="msg" onfocus="if(this.value == 'Your Message*') this.value = ''"
                            onblur="if(this.value == '') this.value = 'Your Message*'">Your Message*</textarea>
            <button id="submit" class="button"> Send Message</button>
          </form>
        </fieldset>
<form id.. name.. method.. action="/handle_post.php">