我已閱讀常量和mail()函數的php.net文檔,但我仍然無法解決當前的問題。在PHP郵件()函數中使用常量時遇到問題
我想建立一個註冊腳本,當表單上的所有內容都正確並通過一些正則表達式檢查時,將用戶添加到數據庫並執行兩項操作:顯示感謝頁面,並通過電子郵件發送電子郵件地址提供了一個感謝信。
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.");
}
}
我成立了DEVEMAIL不斷在我的config.inc.php文件像這樣:
define('DEVEMAIL','[email protected]');
到目前爲止,我此腳本的測試,將這些用戶添加到數據庫並顯示感謝信息,但是當它發送感謝電子郵件時,它來自我的通用主機電子郵件地址,而不是我爲常量設置的電子郵件。我是否正確地在mail()函數中格式化常量?任何感謝,將不勝感激。
編輯:郵件服務器已配置,並正在研究創建預準備語句。非常感謝有用的建議。
裏面工作? –
請切換到[已準備好的語句](http://bobby-tables.com/php.html)以防止SQL注入。並且請刪除您的電子郵件地址以防止收集電子郵件。 –