Wordpress重置密码电子邮件 - 纯文本到HTML

时间:2017-08-31 06:36:40

标签: php wordpress email wordpress-login

我需要以下脚本的帮助

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并仍保留打印网址和用户电子邮件地址的功能?例如;

<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内容和HTML此模板中的内容创建单独的return文件?

总是非常感谢您的时间。

2 个答案:

答案 0 :(得分:0)

是的,Darren Mathers,你可以使用类似的东西

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;

}

答案 1 :(得分:0)

我的问题的解决方案分两部分完成

首先是添加到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标记。

感谢那些对我的解决方案有所帮助的人。