更改主机后Php电子邮件表单脚本无法正常工作

时间:2018-03-09 16:35:27

标签: php forms contact

我只是注册了这个问题,我搜索了十天,我找不到任何解决方案。

我用于我的网站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" );
  }

&GT;

1 个答案:

答案 0 :(得分:0)

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

`
/*
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" );
}

`