Mailer PHP
<?PHP
$to = "phil@gmail.com";
$subject = "Results from your Request Info form";
$headers = "From: Form Mailer";
$forward = 0;
$location = "";
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n";
$msg2 = "Below is the result of your feedback form. It was submitted on $date at $time.<br>";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
$msg2 .= ucfirst ($key) ." : ". $value . "<br>";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
$msg2 .= ucfirst ($key) ." : ". $value . "<br>";
}
}
$sentmail = @mail($to, $subject, $msg, $headers);
if($sentmail){
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email. The message that would have been sent is:<br>";
echo $msg2;
}
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
联系美国页面:
<!DOCTYPE html>
<head>
<meta name="description" content="Contact us" />
<title>Contact Us</title>
<link rel="stylesheet" href="MOstylesheet.css" type="text/css" />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<style>
.mapcenter img{display: block;margin-left:auto; margin-right:auto; border: 1px solid lightgray}
h3 {text-align: center; width: 60%;margin-left: auto;margin-right: auto;}
</style>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
function processForm()
{
if(document.getElementById("p1").value=="")
{
alert("Hi! Your name is required for submission.")
document.getElementById("p1").focus();
}
else if(document.getElementById("p2").value=="")
{
alert("Hi! Your email is required for submission.")
}
else
{
return true;
}
return false;
}
function changeBack()
{
document.getElementById("b1").style.backgroundColor="rgba(205, 24, 24,1)";
}
function changeUp()
{
document.getElementById("b1").style.backgroundColor="rgba(205, 24, 24,0.75)";
}
</script>
</head>
<body>
<form method="post" action="mailer.php" onsubmit="return processForm()">
<div class="background">
<div class="header" id="myHeader">
<div class="ahover">
<table>
<tr id="i2">
<th> <a href="inventory.htm">INVENTORY </a> </th>
<th> <a href="pastsales.htm">PAST SALES </a> </th>
<th> <a href="sell.htm"> SELLING</a> </th>
<th> <a href="index.htm"><img src="MOround.png" id="i1" alt="logo" width="120" height="120"></a></th>
<th> <a href="aboutus.htm">ABOUT US </a> </th>
<th> <a href="ContactUs.htm">CONTACT US</a> </th>
<th> <a href="events.htm">EVENTS</a> </th>
</tr>
</table>
</div>
</div>
<h1>Let's Connect!</h1>
<table>
<tr><td>Your Name: <input id="p1" type="text" name="firstname" maxlength="100" placeholder="First & Last"></td>
<td>Your Email: <input id="p2" type="text" name="email" maxlength="100" placeholder="@"></td>
<td>Your Phone: <input type="text" name="phone" maxlength="100" placeholder="123-456-7890"></td></tr>
</table>
<br>
<br>
<table>
<tr> <td> <textarea name="comments" placeholder="Your Note" rows="10" cols="100"></textarea> </td></tr>
</table>
<div class="display">
<input type="submit" onmouseover="changeUp()" onmouseout="changeBack()" id="b1"class="button" value="Submit" name="Submit"/>
</div>
<br>
<h3>Click on the map for our phone number and the pointer for directions to our warehouse:</h3>
<div class="linkhover">
<div class="mapcenter">
<img id="img1" src="homelogos/googlemap.png" usemap="#image-map" >
<map name="image-map">
<area target="_blank" alt="warehouse" title="warehouse" href="https://www.google.com/maps/dir//210+Kuniholm+Dr+%236,+Holliston,+MA+01746/@42.2292264,-71.4641604,13z/data=!4m8!4m7!1m0!1m5!1m1!1s0x89e477ab59a7f13b:0x61314ee92acc8e13!2m2!1d-71.4290551!2d42.2291682" coords="121,397,258,506" shape="rect">
</map>
</div>
</div>
<br>
<br>
<br>
<hr>
<h5> Copyright</h5>
<h6> Beta Release 4: 06/05/18</h6>
</form>
<script>
window.onscroll = function() {myFunction()};
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
document.getElementById("i1").width="80";
document.getElementById("i1").height="80";
document.getElementById("i2").style.fontSize="14px"
} else {
header.classList.remove("sticky");
document.getElementById("i1").width="120";
document.getElementById("i1").height="120";
document.getElementById("i2").style.fontSize="16px"
}
}
</script>
</body>
</html>
提交时我没有收到任何电子邮件。提交与来自php文档的声明一起确认已发送电子邮件;但是,实际的电子邮件从未收到。我使用了我所参加的课程中的php邮件模板。教师说我们只需编辑电子邮件字段然后添加到我们的publicHTML中,一切都会好的。谢谢你的帮助!