Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Simple email function not working. WordPress


If any one can help me urgently I would be most grateful.

I am trying to get this function below to work but I get a fatal error when the user tries to submit...

It is on a multisite install.

Please live demo here [[LINK href=""]][[/LINK]]

Please just submit <strong>admin</strong> to test error...

Please see my code...

add_filter ("wp_mail_content_type", "my_awesome_mail_content_type");
function my_awesome_mail_content_type() {
return "text/html";

add_filter ("wp_mail_from", "my_awesome_mail_from");
function my_awesome_mail_from() {
return "[email protected]";

add_filter ("wp_mail_from_name", "my_awesome_mail_from_name");
function my_awesome_email_from_name() {
return "My Site Network";

add_filter ("retrieve_password_title", "my_awesome_retrieve_password_title");

function my_awesome_retrieve_password_title() {
return "Create Password";

add_filter ("retrieve_password_message", "my_awesome_retrieve_password_message");
function my_awesome_retrieve_password_message($content, $key) {

global $wpdb;
$user_login = $wpdb->get_var("SELECT user_login FROM $wpdb-<users WHERE user_activation_key = '$key'");

$email_subject = imp_retrieve_password_title();


Hello <?php echo $user_name; ?>,

You have requested to create a password via the <a href="<?php echo wp_login_url("url") ?>" target="_blank" title=""></a>

<a href="<?php echo wp_login_url("url") ?>?action=rp&amp;key=<?php echo $key ?>&amp;login=<?php echo $user_login ?>" title="">To create your own password, please click this link.</a>

<strong>If you did not request a new password, please ignore this email.</strong>


$message = ob_get_contents();
return $message;

Can anyone please help me - thanks you!

Answers (2)


Francisco Javier Carazo Gil answers:

Try to set the filter to accept 2 args:

add_filter ("retrieve_password_message", "my_awesome_retrieve_password_message", 10, 2 );

Josh Cranwell comments:

I've changed that line too...

Which got rid of notice thanks, but now with Dbranes change I'm getting this error.

Fatal error: Call to undefined function imp_retrieve_password_title() in /home/sites/ on line 538

[[LINK href=""]][[/LINK]]


Dbranes answers:

this line looks strange

user_login = $wpdb->get_var("SELECT user_login FROM $wpdb-<users WHERE user_activation_key = '$key'");

i.e. the arrow is pointing in the wrong direction:



You could try this, with the <strong>wpdb->prepare()</strong> function and curly brackets <strong>{$wpdb->users}</strong> :

$user_login = $wpdb->get_var($wpdb->prepare("SELECT user_login FROM {$wpdb->users} WHERE user_activation_key = '%s'",$key));

Josh Cranwell comments:

I've changed that line too...

$user_login = $wpdb->get_var("SELECT user_login FROM $wpdb->users WHERE user_activation_key = '$key'");

OK now I've got this...

Fatal error: Call to undefined function imp_retrieve_password_title() in /home/sites/ on line 538

Dbranes comments:

maybe you want to use


instead of


Josh Cranwell comments:

YEEEEESSS!!! you the man.

Thanks. Can you help me with one more thing and I will add another $10.

Where is says...

Hello <?php echo $user_name; ?>,

How can get the First name of the user and echo it here?


Dbranes comments:

ok great,

sure, you can try

$user = get_user_by('login', $user_login);
echo 'Hello ' . $user->first_name . ' ' . $user->last_name;

Dbranes comments:

and without the echo:

<?php $user = get_user_by('login', $user_login);?>

Hello <?php echo user->first_name; ?> <?php echo user->last_name; ?>,

Josh Cranwell comments:

Perfect Perfect!!

Thank you very much.