首页 \ 问答 \ 联系表单bootstrap php(Contact form bootstrap php)

联系表单bootstrap php(Contact form bootstrap php)

我会在这里挺身而出。 我真的不懂PHP,但我想用它为我正在构建的网站制作一个简单的电子邮件表单。 我把我认为可以工作的东西放在一起,但是当我点击提交时我仍然会收到错误。

任何人都可以告诉我,我做错了什么让它工作?

这是代码(对不起,如果我发布了代码,我没有任何线索,问题是什么):

Contact.html:

  <h1 class="cover-heading">Contact Me</h1>
        <div class="form-area">
          <form role="form" method="post" action="Contact.php">
            <br style="clear:both">

            <div class="form-group">
              <input type="text" class="form-control" id="name" name="name" placeholder="Name"
                required>
            </div>
            <div class="form-group">
              <input type="text" class="form-control" id="email" name="email" placeholder="Email"
                required>
            </div>
            <div class="form-group">
              <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number"
                required>
            </div>
            <div class="form-group">
              <input type="text" class="form-control" id="subject" name="subject" placeholder="Subject"
                required>
            </div>
            <div class="form-group">
              <textarea class="form-control" type="textarea" name="message" id="message" placeholder="Message"
                maxlength="1337" rows="7"></textarea>
              <span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>
            </div>

            <button type="submit" id="submit" name="submit" class="btn btn-lg btn-secondary ">Submit Form</button>

          </form>
        </div>

Contact.php:

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "christopherbare@outlook.com";
$email_subject = "ChristopherBare.com Contact form";

function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}


// validation expected data exists
if(!isset($_POST['name']) ||
    !isset($_POST['subject']) ||
    !isset($_POST['email']) ||
    !isset($_POST['mobile']) ||
    !isset($_POST['message'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
}



$name = $_POST['name']; // required
$email = $_POST['email']; // required
$mobile = $_POST['mobile']; // not required
$subject = $_POST['subject']; //required
$message = $_POST['message']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}

if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}

if(strlen($message) < 2) {
$error_message .= 'The message you entered does not appear to be valid.<br />';
}

if(strlen($error_message) > 0) {
died($error_message);
}

$email_message = "Form details below.\n\n";


function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}



$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Mobile: ".clean_string($mobile)."\n";
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Comments: ".clean_string($message)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>





<?php

}
?>

这是错误:

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['subject']) || !isset($_POST['email']) || !isset($_POST['mobile']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email = $_POST['email']; // required $mobile = $_POST['mobile']; // not required $subject = $_POST['subject']; //required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.
'; } if(strlen($message) < 2) { $error_message .= 'The message you entered does not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Mobile: ".clean_string($mobile)."\n"; $email_message .= "Subject: ".clean_string($subject)."\n"; $email_message .= "Comments: ".clean_string($message)."\n"; // create email headers $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> 

I'm going to be upfront here. I don't really know PHP, but I want to use it to make a simple email form for my website that I'm building. I have put together what I thought would work, but I still get errors when I click submit.

Can anyone just tell me what I'm doing wrong to get it to work?

Here's the code (sorry if I over posted the code, I don't have the slightest clue where the problem is):

Contact.html:

  <h1 class="cover-heading">Contact Me</h1>
        <div class="form-area">
          <form role="form" method="post" action="Contact.php">
            <br style="clear:both">

            <div class="form-group">
              <input type="text" class="form-control" id="name" name="name" placeholder="Name"
                required>
            </div>
            <div class="form-group">
              <input type="text" class="form-control" id="email" name="email" placeholder="Email"
                required>
            </div>
            <div class="form-group">
              <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number"
                required>
            </div>
            <div class="form-group">
              <input type="text" class="form-control" id="subject" name="subject" placeholder="Subject"
                required>
            </div>
            <div class="form-group">
              <textarea class="form-control" type="textarea" name="message" id="message" placeholder="Message"
                maxlength="1337" rows="7"></textarea>
              <span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>
            </div>

            <button type="submit" id="submit" name="submit" class="btn btn-lg btn-secondary ">Submit Form</button>

          </form>
        </div>

Contact.php:

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "christopherbare@outlook.com";
$email_subject = "ChristopherBare.com Contact form";

function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}


// validation expected data exists
if(!isset($_POST['name']) ||
    !isset($_POST['subject']) ||
    !isset($_POST['email']) ||
    !isset($_POST['mobile']) ||
    !isset($_POST['message'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
}



$name = $_POST['name']; // required
$email = $_POST['email']; // required
$mobile = $_POST['mobile']; // not required
$subject = $_POST['subject']; //required
$message = $_POST['message']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}

if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}

if(strlen($message) < 2) {
$error_message .= 'The message you entered does not appear to be valid.<br />';
}

if(strlen($error_message) > 0) {
died($error_message);
}

$email_message = "Form details below.\n\n";


function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}



$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Mobile: ".clean_string($mobile)."\n";
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Comments: ".clean_string($message)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>





<?php

}
?>

Here is the error:

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['subject']) || !isset($_POST['email']) || !isset($_POST['mobile']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email = $_POST['email']; // required $mobile = $_POST['mobile']; // not required $subject = $_POST['subject']; //required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.
'; } if(strlen($message) < 2) { $error_message .= 'The message you entered does not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Mobile: ".clean_string($mobile)."\n"; $email_message .= "Subject: ".clean_string($subject)."\n"; $email_message .= "Comments: ".clean_string($message)."\n"; // create email headers $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> 

原文:https://stackoverflow.com/questions/45003459
更新时间:2022-06-18 20:06

最满意答案

    class Pair<T, U> {
        public final T x;
        public final U y;

        public Pair(T x, U y) {
            this.x = x;
            this.y = y;
        }
    }

    Collector<Aggregate, ?, Pair<Integer, Integer>> aggregateSalary = 
        mapping(a -> new Pair<>(a.getMinSalary(), a.getMaxSalary()),
            reducing(new Pair<>(Integer.MAX_VALUE, Integer.MIN_VALUE),
                (a, b) -> new Pair<>(Math.min(a.x, b.x), Math.max(a.y, b.y))));

    Map<String, Pair<Integer, Integer>> byDepartmentMinMax =
        deptTeamAggregates.stream()
            .collect(groupingBy(a -> a.getDepartment(), aggregateSalary));

    Map<Pair<String, String>, Pair<Integer, Integer>> byDepartmentAndTeamMinMax =
        deptTeamAggregates.stream()
            .collect(toMap(a -> new Pair<>(a.getDepartment(), a.getTeam()), a -> new Pair<>(a.getMinSalary(), a.getMaxSalary())));

    class Pair<T, U> {
        public final T x;
        public final U y;

        public Pair(T x, U y) {
            this.x = x;
            this.y = y;
        }
    }

    Collector<Aggregate, ?, Pair<Integer, Integer>> aggregateSalary = 
        mapping(a -> new Pair<>(a.getMinSalary(), a.getMaxSalary()),
            reducing(new Pair<>(Integer.MAX_VALUE, Integer.MIN_VALUE),
                (a, b) -> new Pair<>(Math.min(a.x, b.x), Math.max(a.y, b.y))));

    Map<String, Pair<Integer, Integer>> byDepartmentMinMax =
        deptTeamAggregates.stream()
            .collect(groupingBy(a -> a.getDepartment(), aggregateSalary));

    Map<Pair<String, String>, Pair<Integer, Integer>> byDepartmentAndTeamMinMax =
        deptTeamAggregates.stream()
            .collect(toMap(a -> new Pair<>(a.getDepartment(), a.getTeam()), a -> new Pair<>(a.getMinSalary(), a.getMaxSalary())));

相关问答

更多
  • class Pair { public final T x; public final U y; public Pair(T x, U y) { this.x = x; this.y = y; } } Collector> aggregateSalary = mapping( ...
  • Stream::min期望符合Comparator合同的东西。 但是Integer::min不会这样做,它只返回其两个输入的最小值。 您应该使用Integer::compare 。 Stream::min expects something that adheres to the Comparator contract. But Integer::min doesn't do that, it just returns the minimum of its two inputs. You should be ...
  • 您的第一个解决方案看起来正确,除了order by子句; 尝试: select Category, min(StartDateTime) [MinStartDateTime], max(EndDateTime) [MaxDateTime] from MyTable group by Category order by Category, MinStartDateTime, MaxDateTime Your first solution looks c ...
  • 让我来解释这里发生了什么,因为它不是很明显! 首先, Stream.max()接受Comparator一个实例,以便流程中的项目可以相互比较,以找到最小或最大值,按照一定的最优顺序,您不用担心太多。 所以问题当然是为什么是Integer::max接受? 毕竟不是比较器! 答案是新的lambda功能在Java 8中起作用。它依赖于非正式地称为“单抽象方法”接口或“SAM”接口的概念。 这个想法是,具有一个抽象方法的任何接口都可以通过任何lambda或方法引用来自动实现 - 其方法签名是接口上的一种方法的匹配。 ...
  • 如果您想要真正的最大值和最小值,只需使用变量跟踪它们即可。 根据您的输入数据,概率最小值/最大值可能“足够准确”。 因此,如果你只看50%几率的每个数字,那么你可能只有50%具有确切的最小值或最大值。 但是,可能已经有75%的机会至少拥有第二大/最小等等。但是,计算随机数进行无偏差抽样已经比查看所有最小/最大数字更昂贵了。 每秒跳过都很危险:数据中可能存在偶数/奇数模式,这会严重影响您。 If you want the true maximum and minimum, just track them wi ...
  • 因为你创建的Comparator总是返回最大的第一个元素。 如果你比较A和B ,如果A更小,你应该返回-1 。 你返回A和B的Integer.max ,在你的情况下,它总是>0 。 (a,b) -> { if (a>b) return 1; // <-- you return a positive value always, so stream.max() thinks 5>8 :) if (a
  • 您可以流式传输数组并从中提取min : MathFunction func = new MathFunction((x) -> Arrays.stream(x).min().getAsDouble()); You could stream the array and extract the min from it: MathFunction func = new MathFunction((x) -> Arrays.stream(x).min().getAsDouble());
  • 您似乎需要将原始Map的每个值映射到相应的最大MyDayObject : List allHighest = weeks.values() // produces a Collection> .stream() // produces a Stream> .map(list -> list.stream() // transforms each List
  • 您可以使用collect()将流的所有元素组合到一个包含所需值的Dimensions对象中。 来自Stream文档: R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner); 对此流的元素执行可变减少操作。 可变减少是其中减少的值是可变结果容器(例如ArrayList),并且通过更新结果的状态而不是通过替换结果 ...
  • 首先,您需要使用组加入 集团加入 带有into表达式的join子句称为组连接。 组连接产生分层结果序列,其将左源序列中的元素与右侧源序列中的一个或多个匹配元素相关联。 小组加入在关系方面没有对应关系; 它本质上是一个对象数组序列。 这是查询 var productListDatabase = from product in DataContext.Products join band in DataContext.ProductClassBands on product.productId equa ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)