我正在使用 php 脚本向给定地址发送电子邮件,但是没有发送电子邮件,即使脚本正在将用户发送到感谢页面。它在一个阶段工作,但随后莫名其妙地停止了。
任何帮助表示赞赏:)
<?php
$to = "emailaddress@gmail.com \r\n";//<== update the email address
$headers = "From: $email_from \r\n";
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'email@mydomain.com';//<== update the email address
$email_subject = "Contact via the website";
$email_body = "You have received a new message from $name.\n\n".
"Here is the message:\n $message\n\n\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: http://domain.com/thank-you/');
// 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;
}
}
?>