我想獲得一個服務器腳本使用wp_mail()併發送電子郵件給用戶。我將此作爲密碼重置例程的一部分,並從用戶那邊用Ajax調用腳本。WordPress的PHP服務器腳本發送電子郵件
我從我的服務器腳本收到以下錯誤:
Fatal error: Call to undefined function wp_mail() in /var/www/abc-php/pwd.php on line 57
我似乎無法找到一個回答我的問題,所以也許我問不正確。我在做什麼?
我的服務器腳本(pwd.php)包含:
<?php
$setFromId = "[email protected]";
$setFromName = "Info @ abc";
$replyToId = "[email protected]";
$replyToName = "Info @ abc";
$sendToEmail = base64_decode($_GET["ste"]); //the URL in AJAX call contains base64 encoded data
$resetPwd = base64_decode($_GET["rp"]);
$resetSalt = base64_decode($_GET["rs"]);
$param = $_GET["var"];
$username = "xxxxxxxxx";
$password = "xxxxxxxx";
$host = "localhost";
$database = "xxxxxxxxx";
$con = mysqli_connect($host, $username, $password, $database);
// Check connection
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
switch ($param) {
case "PWDRES": // Query 1: Current Logged In Partner Details
$mysqli = new mysqli($host, $username, $password, $database);
if (mysqli_connect_errno()) {
echo '<p>Unable to connect to the server at this time to update and send password. Please contact SMA for help or try again.</p>';
} else {
$myquery = "UPDATE abc_users
SET `password` = SHA2('" . $resetPwd . $resetSalt . "', 512),
`salt_value` = SHA2('" . $resetSalt . "', 512)
WHERE email_user_id = '" . $sendToEmail . "'";
mysqli_query($mysqli, $myquery);
if($mysqli->affected_rows >= 1) {
$headers = 'Reply-To: <' . $replyToName . '> ' . $replyToId;
$subject = "Password Reset - Confidential";
$body = "Subject: " . $subject . "<br/><br/>Your new password is: <br/><strong>" . $resetPwd . "</strong><br/><br/>Please ensure you reset this password next time you log in.";
$mail = wp_mail($sendToEmail, $subject, $body, $headers);
echo "Password was successfully reset and sent to " . $sendToEmail;
} else if($mysqli->affected_rows == 0) {
echo "No user id row was updated in the process of resetting password. Please try again.";
} else if($mysqli->affected_rows < 0) {
echo "There was an SQL error updating the user id password table. Please contact SMA for help.";
};
};
break;
case "OTHER1"
etc, etc, etc...
default;
};
};
unset($con);
unset($myquery);
unset($mysqli);
?>
任何幫助表示讚賞。
你把你的'pwd.php'文件放在哪裏???項目根目錄或主題根目錄中的 ??? –
該php文件與其他人創建的網站位於其自己的文件夾中。如www/my-php /文件夾中所示。這是否會影響服務器引用WP功能的能力? – TheRealPapa