我正在尝试编写一个在发布新帖子后向我的用户发送电子邮件的功能。这是我到目前为止所拥有的:
require_once('db.php');
$sql="SELECT email FROM table";
$result = sqlsrv_query($sqlsrvconnection, $sql);
$emailList="";
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
$emailList.=", ".$row['email'];
}
add_action('save_post', 'email_members');
function email_members( $post_id, $emailList ) {
if ( !wp_is_post_revision( $post_id ) ) {
$to = 'example@test.com';
$subject = 'the subject';
$message = "email list consists of: ".$emailList;
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
}
在我的函数中,我尝试传入 $emailList 变量,但我无法用它做任何事情。我传递错了吗?挂钩到另一个 wp 操作时是否不允许这样做?