Php 联系方式,它是如何工作的?
我即将启动我的网站,但首先我需要完成我的联系表,以确保用户可以与我联系。我不是PHP方面的专家,所以请理解我的无知 我已准备好服务器并正在运行。我有一封电子邮件。我有这个网站。我有两个文档,一个是Php 联系方式,它是如何工作的?,php,html,forms,Php,Html,Forms,我即将启动我的网站,但首先我需要完成我的联系表,以确保用户可以与我联系。我不是PHP方面的专家,所以请理解我的无知 我已准备好服务器并正在运行。我有一封电子邮件。我有这个网站。我有两个文档,一个是contact.html,另一个是send.php Mycontact.html包含以下内容: <!doctype html> <html> <head> <title>Spotnight - About</title> <lin
contact.html
,另一个是send.php
Mycontact.html
包含以下内容:
<!doctype html>
<html>
<head>
<title>Spotnight - About</title>
<link rel="stylesheet" href="style.css">
<link rel="Favicon" href="f.ico" type="image/x-icon">
</head>
<body>
<div class="ham_container">
<svg id="hamburger" title="Menu">
<path d="M0,5 30,5" stroke="#eeeeee" stroke-width="5"/>
<path d="M0,14 30,14" stroke="#eeeeee" stroke-width="5"/>
<path d="M0,23 30,23" stroke="#eeeeee" stroke-width="5"/>
</svg>
</div>
<nav>
<ul>
<li><a href="http://spotnight.io/">Our Home</a></li>
<li><a href="http://spotnight.io/about.html">About Us</a></li>
<li><a href="http://spotnight.io/hybon.html">Hybon Sites</a></li>
<li><a href="http://spotnight.io/orion.html">Orion Interactives</a></li>
<li><a href="http://spotnight.io/studios.html">Spotnight Studios</a></li>
<li><a href="http://spotnight.io/shop.html">Spotnight Shop</a></li>
<br>
<li><a href="http://spotnight.io/contact.html">Contact Us</a></li>
</ul>
</nav>
<main>
<h1>Contact us! :)</h1>
<h5>Spotnight</h5>
<div>
<form action="send.php" method="POST">
<input type="text" name="first_name" placeholder="Your first name, eg: 'John'">
<input type="text" name="last_name" placeholder="Your last name, eg: 'Smith'">
<input type="email" name="email" placeholder="Your Email, eg: 'yourname@example.com'">
<select name="subj" size="1">
<option value="new_website">I need a website</option>
<option value="new_game">I want a game</option>
<option value="new_employee">I want to be part of the team</option>
<option value="new_employee_game">I want to participate making games</option>
<option value="new_employee_site">I want to participate building sites</option>
<option value="new_artist">I'm an artist and need help</option>
<option value="something_else">Something else!</option>
</select>
<textarea name="message" placeholder="Your Message Goes Here!"></textarea>
<input type="submit" value="Send!">
</form>
</div>
</main>
<footer>
© <span id="year">2015</span> : <a href="http://hybon.spotnight.io/">Spotnight.io</a> : Proudly created by Hybon.
</footer>
</body>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="script.js"></script>
</html>
<!doctype html>
<html>
<head>
</head>
<body>
<?php
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$subj = $_POST["subj"];
$message = $_POST["message"];
$formcontent="From: " . $first_name . $last_name . ", " . $email . "\n Subject: " . $subj . "\n Message: " . $message;
$recipient = "julian-avar@spotnight.io";
$subject = "Contact Form - " . $subj . " - Spotnight.io";
$mailheader = $email . " has tryed to reach you! \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Your message has been recived, we'll answer as soon as possible!" . $first_name . $last_name . " -" . "<a href="contact.html">Go Back!</a>";
?>
</body>
</html>
这都是文字,意思是,代码就在那里。我很难理解它,但我仍然不明白它是如何工作的
所以,如果你是一个超级复制者可怕的php专家,请帮助我理解和修复这段代码,以便我以后可以处理它,让其他人了解它是如何工作的
我已经搜索了很多地方,但是最简单的联系方式在世界档案馆中没有出现。多谢各位 您的'send.php'脚本将html与php混合在一起,因此除非您使用输出缓冲,否则由于html内容已发送到客户端/浏览器,您在尝试发送电子邮件时将遇到错误。我建议send.php脚本仅为纯php。另外,mailheader变量-我觉得这是错误的-我认为它至少应该包含From:email@domain.com领域从PHP手册:
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
<?php
/* send.php */
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$subj = $_POST["subj"];
$message = $_POST["message"];
$formcontent="From: " . $first_name . $last_name . ", " . $email . "\n Subject: " . $subj . "\n Message: " . $message;
$recipient = "julian-avar@spotnight.io";
$subject = "Contact Form - " . $subj . " - Spotnight.io";
$mailheader = "From: ".$email . "\r\n";
$res = mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
if( $res ) header( 'location:/index.php?mailsent=true' );
else header( 'location:/index.php?mailsent=false' );
?>
$to='1!'nobody@example.com';
$subject='主题';
$message='hello';
$headers='来自:webmaster@example.com' . “\r\n”。
答复:webmaster@example.com' . “\r\n”。
“X-Mailer:PHP/”。phpversion();
邮件($to、$subject、$message、$headers);
echo“谢谢!您的邮件已收到,我们将尽快回复!”$名字$姓。" -" . "";
问题出在这里。因此,SO的代码Highlil严重突出了它
改用这个:
echo /* part of code missing */ $first_name . $last_name . " -" . "<a href='contact.html'>Go Back!</a>";
// mind the ' signs here ^^^^^^^^^^^^^
echo/*部分代码缺少*/$first\u name$姓。" -" . "";
//注意这里的标志^^^^^^^^^^^^^
如果不转义“'s”或使用单个引号(我可能在术语上弄错了)符号,则无法在另一个引号中包含引号。这看起来像是一个简单的错误,在$formcontent行中,您以$message结尾”;移除,所以它看起来像:$message;谢谢,我没有看到,但即使在我更新了它之后,它似乎仍然不起作用,它只是给我显示了一个空白页面,上面有
send.php
@julian.a.avar-听起来你的服务器不支持php。是的,它支持,我使用的是免费服务器x10hosting,但即使在免费的服务器上,他们支持PHP5,你也无法从浏览器中跟踪PHP代码。。它是一种服务器端语言..浏览器甚至不知道使用了什么类型的服务器脚本等待什么?我很困惑,我应该改变什么?contact.html
必须被包围,
不是“
”谢谢你,这帮了大忙。现在它显示了文本,但我已经等了五分钟,我使用的服务器并没有那么慢,所以它似乎无法解决所有问题。…。@julian.a.avar,你的代码有效吗?如果没有,到底是什么不起作用?它会发送电子邮件吗?它仍然不会,但现在我正在看清除所有HTML是否有帮助,所以我只使用
并删除所有HTML,还有什么?因为我希望电子邮件包含所有这些信息,我不希望它只包含这三样东西:主题、消息和标题。上面的例子就是一个例子。您仍然可以包括在“send.php”脚本中设置的各种变量,但不需要html标记。邮件发送后,您可以使用标题将用户重定向回html页面。(header('location:/index.php')等),因此我只删除所有HTML并坚持使用
?感谢您的帮助,但似乎我根本不需要删除HTML。由于HTML内容已发送到客户端/浏览器,因此它尝试发送电子邮件时出错。-胡说如果尝试发送HTTP响应头,则会出现该错误。发送电子邮件完全独立于构造HTTP响应。
echo /* part of code missing */ $first_name . $last_name . " -" . "<a href='contact.html'>Go Back!</a>";
// mind the ' signs here ^^^^^^^^^^^^^