【问题标题】:Php Email forms script not working after change hosting更改托管后 PHP 电子邮件表单脚本不起作用
【发布时间】:2018-03-09 16:35:27
【问题描述】:

我刚刚注册这个问题,我搜索了十天,我没有找到任何解决方案。

我为我的网站使用 php 和简单的 HTML 表单。在我更改主机提供商后,表单停止工作。 在我完成表格并按提交后,将您发送到错误页面,并且没有电子邮件发送给我。

我有旧主机,我使用相同的文件,没有任何变化,它正在工作。 我试图在 cpanel 中更改 php 版本,但没有出现同样的错误。 我已经尝试过其他简单的脚本并且它正在工作,所以我不需要 smtp 来发送电子邮件。

    <?
$numele=$_REQUEST['nume'];
$adresa=$_REQUEST['email'];
$telefon=$_REQUEST['tel'];
$comentariu=$_REQUEST['comentar'];
$catre="contact@mysite.ro";
$siteaddress ="http://www.mysite.ro";
$sitename = "Mysite.ro";

$mesaj="Un vizitator pe mysite.ro a lasat urmatorul mesaj:\n
Nume: $numele
Email: $adresa
Telefon: $telefon

Mesaj:
------------------------------
$comentariu";




if (!isset($_REQUEST['email'])) {
    header( "Location: http://www.mysite.ro/index.html" );
  }
  elseif (empty($email) || empty($comentariu) || empty($numele) || empty($telefon)) {
    header( "Location: http://www.musite.ro/contact-eroare.html" );
  }
  else {
    mail($catre,"Contact Muri.ro",$mesaj,"From: $email" );
    header( "Location: http://www.mysite.ro/contact-mesaj-trimis.html" );
  }



//This sends a confirmation to your visitor
if (!isset($_REQUEST['email'])) {
    header( "Location: http://www.mysite.ro/index.html" );
  }
  elseif (empty($email) || empty($comentariu) || empty($numele) || empty($telefon)) {
    header( "Location: http://www.mysite.ro/contact-eroare.html" );
  }
  else {
    mail("$email","Multumim pentru interesul acordat produselor oferite de noi.",
    "Buna $numele,\n

Mesajul dvs. a fost inregistrat! Promitem sa raspundem in maxim 24 de ore. \n

Cu respect,
$sitename
$siteaddress
$catre","FROM:$catre");
    header( "Location: http://www.mysite.ro/contact-mesaj-trimis.html" );
  }

?>

【问题讨论】:

标签: php forms contact


【解决方案1】:

感谢您的回复! 我尝试了代码仍然无法正常工作,同样的问题:( 看我使用下面的代码,它运行得很好,但它不像上一个那么好。

`
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "contact@mysite.ro";

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "produse.html";
$error_page = "contact-eroare.html";
$thankyou_page = "contact-mesaj-trimis.html";

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$email_address = $_REQUEST['email'] ;
$comments = $_REQUEST['comentar'] ;
$first_name = $_REQUEST['nume'] ;
$telef = $_REQUEST['tel'] ;
$msg =
"Nume: " . $first_name . "\r\n" . 
"Telefon: " . $telef . "\r\n" . 
"Email: " . $email_address . "\r\n" . 
"Mesaj:
" . 
$comments ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
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;
    }
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['email'])) {
header( "Location: $feedback_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($first_name) || empty($email_address) || empty($telef)) {
header( "Location: $error_page" );
}

/* 
If email injection is detected, redirect to the error page.
If you add a form field, you should add it here.
*/
elseif ( isInjected($email_address) || isInjected($first_name) || isInjected($telef)  || isInjected($comments) ) {
header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {

    mail( "$webmaster_email", "Contact mysite.ro", $msg );

    header( "Location: $thankyou_page" );
}

`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2012-09-27
    • 1970-01-01
    • 2010-12-23
    相关资源
    最近更新 更多