gpt4 book ai didi

php - 带有 html 和 php 的联系表单

转载 作者:行者123 更新时间:2023-11-27 23:43:09 24 4
gpt4 key购买 nike

Hi im a newbie so i tried to use some source code to create a contact form for my website it does not work so i need help here is my code: 

HTML

<div class="col-md-6 col-sm-6">
<div class="row contact-form">
<form id="contact-form" action="php/mail.php">
<fieldset class="col-md-6 col-sm-6">
<input id="name" type="text" name="name" placeholder="Name">
</fieldset>
<fieldset class="col-md-6 col-sm-6">
<input type="email" name="email" id="email" placeholder="Email">
</fieldset>
<fieldset class="col-md-12">
<input type="text" name="subject" id="subject" placeholder="Subject">
</fieldset>
<fieldset class="col-md-12">
<textarea name="comments" id="comments" placeholder="Message"></textarea>
</fieldset>
<fieldset class="col-md-12">
<input type="submit" name="send" value="Send Message" id="submit" class="button">
</fieldset>
</form>
</div> <!-- /.contact-form -->
</div> <!-- /.col-md-6 -->

PHP

<?php
include 'functions.php';

if (!empty($_POST)){
$data['success'] = true;
$_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);

// your email adress
$emailTo ="brinny@abvconstruction.co.za"; // "yourmail@yoursite.com";

// from email adress
$emailFrom ="contact@yoursite.com"; // "contact@yoursite.com";

// email subject
$emailSubject = "Mail from Web Contact Form ";

$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if($name == "")
$data['success'] = false;

if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;


if($comment == "")
$data['success'] = false;

if($data['success'] == true){
$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);

$data['success'] = true;
echo json_encode($data);
}
}

Thank you. I changed the code to this :

<?php

include 'functions.php';

if (!empty($_POST)){

$data['success'] = true;


//your email adress
$emailTo ="brinny@abvconstruction.co.za"; //"yourmail@yoursite.com";

//from email adress
$emailFrom = $_POST["email"]; //"contact@yoursite.com";

//email subject
$emailSubject = $_POST["subject"];

$name = $_POST["name"];
$email = $_POST["email"];
$comments = $_POST["comments"];
if($name == "")
$data['success'] = false;

if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
$data['success'] = false;


if($comments == "")
$data['success'] = false;

if($data['success'] == true){

$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comments";


$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=utf-8" . "\r\n";
$headers .= "From: <$emailFrom>" . "\r\n";
mail($emailTo, $emailSubject, $message, $headers);

$data['success'] = true;
echo json_encode($data);
}`enter code here`
}

我还想知道我是否应该使用 php_redirect 让浏览器打开 html 文件而不是 php 文件

网站是 abvconstruction.co.za。如果有人可以检查我的代码有什么错误

最佳答案

首先,您必须添加 method="post"给你的<form> ,否则它将使用 GET 发送数据。

同时删除这些清除 POST 数据的行:

$_POST  = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST = multiDimensionalArrayMap('cleanData', $_POST);

关于php - 带有 html 和 php 的联系表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31025948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com