PHP联系人表格(sendmail)未收到电子邮件

时间:2018-06-25 09:45:37

标签: javascript php

下面是我在网站上使用的联系表单的代码。

我似乎无法使其工作(不接收电子邮件),并且希望将其发送成功后重定向到主页。感谢您的帮助!

<?php
// Variables
/*
*SendMail: by fb.com/nurealamsabbir
*/
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);
$select_industry = trim($_POST['select_industry']);
// $subject= trim($_POST['subject']);
$subject = 'Message From caracraft';
if(!$subject) {
    $subject = 'Message From caracraft';
}
$to = "example@gmail.com"; // Change with your email address
//echo "{$to}";
if( isset($name) && isset($email) ) {

    // Avoid Email Injection and Mail Form Script Hijacking
    $pattern = "/(content-type|bcc:|cc:|to:)/i";
    if( preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $message) ) {
        exit;
    }
    // Email will be send

//Must end on first column

    $headers = "From: $name <$email>\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // PHP email sender
    mail($to, $sub, $body, $headers);

    // PHP email sender
  if(mail( "getthemesopera@gmail.com", $_POST['subject'], $_POST['message'], $headers )){
    echo "Thank you, I have received your message.";
  }
  else {
    echo "Email cannot be sent now. Please try later.";
  }
  //  Replace with your email 
  return false;
}

?>

0 个答案:

没有答案