1

我需要以下脚本的帮助

public function replace_retrieve_password_message( $message, $key, $user_login, $user_data ) {
    // Create new message
    $msg  = __( 'Hello!', 'personalize-login' ) . "\r\n\r\n";
    $msg .= sprintf( __( 'You asked us to reset your password for your account using the email address %s.', 'personalize-login' ), $user_login ) . "\r\n\r\n";
    $msg .= __( "If this was a mistake, or you didn't ask for a password reset, just ignore this email and nothing will happen.", 'personalize-login' ) . "\r\n\r\n";
    $msg .= __( 'To reset your password, visit the following address:', 'personalize-login' ) . "\r\n\r\n";
    $msg .= site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "\r\n\r\n";
    $msg .= __( 'Thanks!', 'personalize-login' ) . "\r\n";

    return $msg;
}

这是替换Wordpress 重置密码电子邮件。它的功能很好,并且正在发挥作用。但是,它不是很漂亮,我想用HTML电子邮件替换它。

有没有办法我可以添加HTML到这个并且仍然保留打印 URL 和用户电子邮件地址的功能?例如;

<div>
  <h1>Hello</h1>
  <p>You asked us to reset your password for your account using the email address <?php PRINT USER EMAIL ?></p>
  <a href="<?php PRINT URL ?></a>
</div>

我知道上面是非常基本的并且PHP不正确但是如果我想Plain Text用这个替换电子邮件,我该怎么做?是否可以使用该模板的内容和 内容创建一个单独的PHP文件?HTMLreturn

非常感谢您的时间。

4

2 回答 2

1

我的问题的解决方案分为两部分

首先是添加到functions.php

function email_set_content_type(){
return "text/html";
}

add_filter( 'wp_mail_content_type','email_set_content_type' );

第二个是在自定义插件中添加的,如下所示

    $msg  = __( "<div><h1>Hello!</h1>", 'personalize-login' ) . "\r\n\r\n";
    $msg  = __( "<p>You asked us to reset your password for your account using the email address", 'personalize-login' ) . "\r\n\r\n";
    $msg .= sprintf( __( "%s.</p>", 'personalize-login' ), $user_login ) . "\r\n\r\n";
    $msg .= __( "<a href='", 'personalize-login' ) . "\r\n\r\n";
    $msg .= site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "\r\n\r\n";
    $msg .= __( "'></a></div>", 'personalize-login' ) . "\r\n\r\n";

    return $msg;

我现在已经使用这种方法将所有核心 Wordpress 消息替换为整个模​​板,email包括标签。html bodyhead

感谢那些对我的解决方案提出意见的人。

于 2017-08-31T09:18:38.030 回答
0

是的,达伦·马瑟斯,你可以使用类似的东西

function replace_retrieve_password_message($message, $key, $user_login,   $user_data) {
// Create new message

  $msg  = '<div><h1>Hello!, personalize-login</h1>';
  $msg .= '<p>You asked us to reset your password for your account using the email address personalize-login </p>'.$user_login;
  $msg .= "<p>If this was a mistake, or you didn't ask for a password reset, just ignore this email and nothing will happen personalize-login";
  $msg .= '<p> To reset your password, visit the following address: personalize-login';

  $msg .= '<p>'.site_url( "wp-login.php?action=rp&key=$key&login=".rawurlencode($user_login),'login').'</p>' 
  $msg .= '<p>Thanks! personalize-login</p> </div>';

  return $msg;

}
于 2017-08-31T07:17:55.240 回答