<form action="form-to-email.php" method="post">
<p><label for='name'> Name: </label><br/><input type="text" name="Name" /></p>
<p><label for='Subject'> Subject: </label> <br/><input type="text" name="Subject" /></p>
<p><label for='email'> E-Mail: </label> <br/><input type="text" name="email" /></p>
<p><label for='message'>Message:</label><br/><textarea name='message' cols="40" rows="8">
</textarea></p>
<input type="submit" name='submit' class="submit" value="submit"/> <br/>
</form>
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['Name'];
$visitor_email = $_POST['email'];
$Subject = $_POST['Subject'];
$message = $_POST['message'];
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'email@website.com';
$email_subject = "New Form submission:\n $Subject";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "businessemail@email.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thankyou.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
php是一个复制/粘贴工作,用于工作。但我最近发现它现在不起作用了。我正在使用godaddy来托管使用cPanel Hosting。