0

我已经阅读了关于常量和 mail() 函数的 php.net 文档,但我仍然无法解决我当前的问题。

我正在尝试构建一个注册脚本,当表单上的所有内容都正确并通过一些正则表达式进行检查时,将用户添加到数据库并做两件事:显示感谢页面,并通过电子邮件发送电子邮件地址提供感谢笔记。

 if(empty($reg_errors)) {
        $q = "SELECT email, username FROM users WHERE email = '$e' OR username = '$u'"; //the mysql query to check for dupe emails/users
        $r = mysqli_query($dbc, $q);
        $rows = mysqli_num_rows($r);
        if($rows==0) {                                 // no dupes of email or user, so let's add them into the DB!
            $q = "INSERT INTO users(username,email,pass,first_name,last_name,date_expires) VALUES('$u','$e','".get_password_hash($p)."','$fn','$ln',ADDDATE(NOW(),INTERVAL 1 MONTH))";
            $r = mysqli_query($dbc, $q);

            //asks DB if a new row was created, and if so, thanks user for registration on the site & sends an email to their email.
            //if query doesnt work, an error is triggered
            if(mysqli_affected_rows($dbc)==1) {
                echo '<h3>Thanks!</h3><p>Thank you for registering! You may now log in and access the site\'s content.</p>';
                $body = "Thanks for registering at Knowledge is Power. We greatly appreciate your interest in our services.\n\n";
                mail($_POST['email'],'Registration Confirmation for Knowledge is Power',$body, 'From:DEVEMAIL');
                include('./includes/footer.inc.php');
                exit();
            } else {
                trigger_error("You could not be registered due to a system error. W apologize for any inconvenience.");
            }
        } 

我在我的 config.inc.php 文件中设置了 DEVEMAIL 常量,如下所示:

define('DEVEMAIL','something@thisplace.com');

到目前为止,在我对此脚本的测试中,它会将用户添加到数据库并显示感谢消息,但是当它发送感谢电子邮件时,它来自我的通用主机电子邮件地址,而不是我为持续的。我是否错误地格式化了 mail() 函数中的常量?任何感谢将不胜感激。

编辑:邮件服务器已配置,并正在研究创建准备好的语句。非常感谢您的有用建议。

4

1 回答 1

4

你要

'From:'.DEVEMAIL 

常量在引号内不起作用

于 2013-07-24T18:54:00.133 回答