我已经阅读了关于常量和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()函数中格式化常量不正确吗?非常感谢。
编辑:配置邮件服务器,并研究创建预准备语句。非常感谢有用的建议。
答案 0 :(得分:4)
你想要
'From:'.DEVEMAIL
常量不能在引号
中使用