为什么此电子邮件表单不发送电子邮件?

时间:2013-07-10 16:19:26

标签: php

嘿,所以我在这里再试一次,我将尝试发布整个代码,看看能否得到一些我可以使用的帮助。所以我有一个3阶段的页面,这样就分解了,主代码假设是在/ root /文件夹上的registration.php页面上。

registration.php (位置:/ root /)

<?php
/*
UserCake Version: 2.0.2
http://usercake.com
*/

require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}

//Prevent the user visiting the logged in page if he/she is already logged in
if(isUserLoggedIn()) { header("Location: account.php"); die(); }

//Forms posted
if(!empty($_POST))
{
$errors = array();
$email = trim($_POST["email"]);
$username = trim($_POST["username"]);
$displayname = trim($_POST["displayname"]);
$password = trim($_POST["password"]);
$confirm_pass = trim($_POST["passwordc"]);
$captcha = md5($_POST["captcha"]);

if ($captcha != $_SESSION['captcha'])
{
$errors[] = lang("CAPTCHA_FAIL");
}
if(minMaxRange(5,25,$username))
{
$errors[] = lang("ACCOUNT_USER_CHAR_LIMIT",array(5,25));
}
if(minMaxRange(5,25,$displayname))
{
$errors[] = lang("ACCOUNT_DISPLAY_CHAR_LIMIT",array(5,25));
}
if(!ctype_alnum($displayname)){
$errors[] = lang("ACCOUNT_DISPLAY_INVALID_CHARACTERS");
}
if(minMaxRange(8,50,$password) && minMaxRange(8,50,$confirm_pass))
{
$errors[] = lang("ACCOUNT_PASS_CHAR_LIMIT",array(8,50));
}
else if($password != $confirm_pass)
{
$errors[] = lang("ACCOUNT_PASS_MISMATCH");
}
if(!isValidEmail($email))
{
$errors[] = lang("ACCOUNT_INVALID_EMAIL");
}
//End data validation
if(count($errors) == 0)
{   
//Construct a user object
$user = new User($username,$displayname,$password,$email);

//Checking this flag tells us whether there were any errors such as possible data duplication occured
if(!$user->status)
{
if($user->username_taken) $errors[] = lang("ACCOUNT_USERNAME_IN_USE",array($username));
if($user->displayname_taken) $errors[] =            lang("ACCOUNT_DISPLAYNAME_IN_USE",array($displayname));
if($user->email_taken)    $errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email));       
}
else
{
//Attempt to add the user to the database, carry out finishing  tasks like emailing the user (if required)
if(!$user->userCakeAddUser())
{
if($user->mail_failure) $errors[] = lang("MAIL_ERROR");
if($user->sql_failure)  $errors[] = lang("SQL_ERROR");
}
}
}
if(count($errors) == 0) {
$successes[] = $user->success;
}
}

require_once("$template/head.php");

//Links Guide Web Design1

putenv('DORUMENT_ROOT=');
$docroot='';

putenv('DORUMENT_ROOT=');
$dir_home_web_design1='../';

putenv('DORUMENT_ROOT=');
$class_home_web_design1='';

putenv('DORUMENT_ROOT=');
$dir_login_web_design1='';

putenv('DORUMENT_ROOT=');
$class_login_web_design1='current';

//Links Guide Web Design1

echo "

<body >

<!-- header -->
<div>";
include "$template/header.php";
echo "

</div>
<!-- header -->

<!-- register -->
<div>";
include "$template/register.php";
echo "

</div>
<!-- register -->

<!-- footer -->
<div>";
include "$template/footer.php";
echo "

</div>
<!-- footer -->

<!-- Javascript - jQuery -->
<script src='http://code.jquery.com/jquery.min.js'></script>
<script>window.jQuery || document.write('<script src='js/jquery-1.7.2.min.js'>    <\/script>')</script> 

</body>
</html>";

?>

链接到另一个注册页面/ roots / models / template / chooser /其中包含电子邮件表单:

注册(位置:/ roots / models / template / chooser /)

<?php

echo "

<!-- register -->

<div class='whiteattire'

<div id='regbox'>

<div id='wrap'>
<div class='container3'>
<div class='row'>
<div class='span3 hidden-phone'></div>
<div class='span6' id='form-login'>
<form name='htmlform' action='$template/email.php' method='post' class='form-horizontal well' >
<fieldset>
<legend>Register for an account</legend>";

echo resultBlock($errors,$successes);

echo "

<br>
<div class='control-group'>
<div class='control-label'>
<label>Name</label>
</div>
<div class='controls'>
<input type='text' placeholder='Type name' name='name' class='input-large'>
</div>
</div>

<div class='control-group'>
<div class='control-label'>
<label>E-mail</label>
</div>
<div class='controls'>
<input type='text' placeholder='Type e-mail' name='email' class='input-large'>

</div>
</div>

<div class='control-group'>
<div class='control-label'>
<label>Telephone</label>
</div>
<div class='controls'>
<input type='text' placeholder='Type telephone' name='telephone' class='input-large'>

</div>
</div>      

<div class='control-group'>
<div class='control-label'>
<label>Password</label>
</div>
<div class='controls'>
<input type='text' placeholder='Type password' name='password' class='input-large'>

</div>
</div>      

<div class='control-group'>
<div class='control-label'>
<label>Security Code:</label>
</div>
<div class='controls'>
<img src='models/captcha.php'>

</div>
</div>  

<div class='control-group'>
<div class='control-label'>
<label>Enter Security Code:</label>
</div>
<div class='controls'>
<input type='text' placeholder='Type code' name=captcha' class='input-large'>

</div>
</div>                                                                          

<div class='control-group'>
<div class='controls'>

<button type='submit' id='submit' class='btn btn-primary button-loading' data-loading-text='Loading...'>&nbsp;&nbsp;&nbsp;&nbsp;Submit&nbsp;&nbsp;&nbsp;&nbsp;</button>

<br></br>

<button type='button' class='btn btn-secondary button-loading' data-loading-text='Loading...'><a href='forgot-password.php'>Forgot Password</a></button>

<button type='button' class='btn btn-secondary button-loading' data-loading-text='Loading...'>&nbsp;&nbsp;<a href='login.php'>Log in</a>&nbsp;&nbsp;</button>                           

</div>
</div>
</fieldset>
</form>

</div>
<div class='span3 hidden-phone'></div>
</div>
</div>
<div id='push'></div>
</div>

</div>

</div>

<!-- register -->
<!-- register -->
<!-- register -->

";

?>  

链接到另一个email.php页面,该页面假设是创建电子邮件并发送它。我正在回复主要注册页面的电子邮件表格遇到麻烦。我想我可能错误地设置了电子邮件代码,这就是为什么我收到500错误,说第18行有问题。这是电子邮件代码,希望你们可以提供帮助:

email.php (位置:/ roots / models / template / chooser /)

<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
            $email_to = "danielobo2@yahoo.com";
            $email_subject = "Registering to blanky-store.net web design account.";

            //Forms posted
            if(!empty($_POST))
            {
            $errors = array();
            $email = trim($_POST["email"]);
            $name = trim($_POST["name"]);
            $telephone = trim($_POST["telephone"]);
            $password = trim($_POST["password"]);
            $captcha = md5($_POST["captcha"]);

            if ($captcha != $_SESSION['captcha'])
            $errors[] = lang("CAPTCHA_FAIL");

            if(minMaxRange($name))
            $errors[] = lang("CONFIG_NAME_CHAR_LIMIT");

            if(!ctype_alnum($name))
            $errors[] = lang("ACCOUNT_DISPLAY_INVALID_CHARACTERS");

            if(!isValidEmail($telephone))
            $errors[] = lang("ACCOUNT_DISPLAY_CHAR_LIMIT");

            if(minMaxRange(8,50,$password) && minMaxRange(8,50,$confirm_pass))
            $errors[] = lang("ACCOUNT_PASS_CHAR_LIMIT",array(8,50));

            if(!isValidEmail($email))
            $errors[] = lang("ACCOUNT_INVALID_EMAIL");


            //End data validation
            if(strlen($error_message) > 0) {
            echo($error_message);
            }               
            $email_message = "Form details below.\n\n";

            function clean_string( $mystring )
            {
            $bad = array("content-type","bcc:","to:","cc:","href");
            return str_replace($bad,"",$mystring);
            }

            $email_message .= "Name: ".clean_string($name)."\n";
            $email_message .= "Email: ".clean_string($email_from)."\n";
            $email_message .= "Telephone: ".clean_string($telephone)."\n";
            $email_message .= "Password: ".clean_string($password)."\n";

            // create email headers
            $headers = 'From: '.$email_from."\r\n".
                                    'Reply-To: '.$email_from."\r\n" .
                                    'X-Mailer: PHP/' . phpversion();
            @mail($email_to, $email_subject, $email_message, $headers); 

            if (mail($email_to, $email_subject, $email_message, $headers))
            header("Location: http://blanky-store.net/index.php");
            }
    }      
die();
?>

我的问题是可以发布整个代码来正确修复此电子邮件表单吗?为什么此电子邮件表单不发送电子邮件?

2 个答案:

答案 0 :(得分:1)

我认为您需要将require_once("models/config.php");放在email.php

的顶部
<?php
if(isset($_POST['email'])) {
  require_once("models/config.php");

email.php中的第18行

$errors[] = lang("CAPTCHA_FAIL");

因为我在代码中的任何地方都没有看到function lang(),所以我认为它位于models/config.php中,因此您的页面因为函数未定义而执行致命错误。


调试代码时,有必要打开php错误报告 -

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

if(isset($_POST['email'])) {
  require_once("models/config.php");

这会将错误输出到页面,以便您自己调试。

答案 1 :(得分:0)

您正在telephone验证validemail function在您的代码中查看此内容

if(!isValidEmail($telephone))
    $errors[] = lang("ACCOUNT_DISPLAY_CHAR_LIMIT");

同时替换代码

//End data validation
if(strlen($error_message) > 0) {
    echo($error_message);
}  

通过

//End data validation
if(count($errors) > 0) {
   echo($error_message);
}