Php 发送到电子邮件的HTML表单
我的Php 发送到电子邮件的HTML表单,php,html,Php,Html,我的html表单发送到电子邮件时出现问题 我已经将它设置为一个php文件,它可以正常工作,但是当我将文件名从index.php更改为contact.php时,它就不再发送了 contact.php: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style/stylesheet.css"> <script src="script/s
html
表单发送到电子邮件时出现问题
我已经将它设置为一个php文件,它可以正常工作,但是当我将文件名从index.php更改为contact.php时,它就不再发送了
contact.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style/stylesheet.css">
<script src="script/scripts.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
<div class="banner">
<img src="images/banner.jpg">
</div>
<div class="navigation">
<div class="navbar">
<a href="index.html" class="active">Home</a>
<a href="news.html">News</a>
<div class="dropdown">
<button class="dropbtn">Parts
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="cases.html">Cases</a>
<a href="motherboards.html">Motherboards</a>
<a href="processors.html">Processors</a>
<a href="graphics.html">Graphics Cards</a>
<a href="storage.html">Storage</a>
<a href="powersupplies.html">Power Supplies</a>
<a href="ram.html">RAM</a>
<a href="other.html">Other</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Builds
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Placeholder</a>
<a href="#">Placeholder</a>
<a href="#">Placeholder</a>
<a href="#">Placeholder</a>
<a href="#">Placeholder</a>
<a href="#">Placeholder</a>
<a href="#">Placeholder</a>
<a href="#">Placeholder</a>
</div>
</div>
<div class="contact" id="navright">
<a href="contact.html" style="float:right;">Contact</a>
</div>
</div>
</div>
<div class="contact_page">
<form class="contact_form" action="contactform.php" method="post">
<label>Full Name:</label><br/>
<input type="text" name="name" placeholder="Full Name"><br/>
<label>Your Email:</label><br/>
<input type="text" name="mail" placeholder="Email"><br/>
<label>Subject:</label><br/>
<input type="text" name="subject" placeholder="Subject"><br/>
<label>Message:</label><br/>
<textarea name="message" class="contacttext" placeholder="Message..."></textarea><br/>
<button class="submit" type="submit">Submit</button>
</form>
</div>
<div class="footer">
<div class="footertext">
<p>Here at Terry's Computers we do not claim to own any of
the products showed on this website.</p>
<a href="contact.html"><p>Contact Us</p></a>
</div>
</div>
</body>
</html>
部分
建立
全名:
您的电子邮件:
主题:
消息:
提交
在特里的电脑里,我们并不声称拥有任何
本网站上展示的产品
contactform.php:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "terryjtowell@terrytowell.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an Email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.php?mailsend");
}
?>
它不是我的web hoster,因为它与此文件一起工作
index.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta charset="UTF-8">
<title>Email Form</title>
</head>
<body>
<main>
<p class="header">E-MAIL FORM</p>
<form class="contact-form" action="contactform.php" method="post">
<p class="title">Your Name</p>
<input type="text" name="name" placeholer="Full Name"><br/>
<p class="title">Your E-Mail</p>
<input type="text" name="mail" placeholer="Your E-mail"><br/>
<p class="title">Subject</p>
<input type="text" name="subject" placeholer="Subject"><br/>
<p class="title">Message</p>
<textarea name="message" maxrows="10" placeholder="Message"></textarea><br/>
<button type="submit" name="submit"><h2>SUBMIT</h2></button><br/>
</form>
</main>
</body>
</html>
电子邮件表格
电子邮件表单
您的姓名
您的电子邮件
主题
消息
提交
您的PHP行:
if (isset($_POST['submit'])) {
将永远不会执行,因为您需要一个名为submit的元素,但您有:
<button class="submit" type="submit">Submit</button>
提交
你在例子中所说的有效。解决方案应该非常简单,只需添加如下名称属性:
<button class="submit" name="submit" type="submit">Submit</button>
提交
您的PHP行:
if (isset($_POST['submit'])) {
将永远不会执行,因为您需要一个名为submit的元素,但您有:
<button class="submit" type="submit">Submit</button>
提交
你在例子中所说的有效。解决方案应该非常简单,只需添加如下名称属性:
<button class="submit" name="submit" type="submit">Submit</button>
提交
通常使用index.php返回相同的内容,但清除所有输入。url从index.php更改为index.php?mailsend,但新文件没有这样做,它在提交后会进入一个空白的白色页面–terryjtowell 37分钟前删除index.php通常会返回相同的内容,但所有输入都已清除。url从index.php更改为index.php?mailsend,但新文件没有这样做,它在提交后会进入一个空白的白色页面–terryjtowell 37分钟前删除