0

When the email content contains a link with url like: mobileappname://accesstoken#w34rdgtsrt5v6m, <a href="mobileappname://accesstoken#w34rdgtsrt5v6m">Click</a> wp_mail function removing the url from the anchor tag and the link doesn't work. When the url is appended with/having http://, the link works. Here is the code I am using. Any help or hint will be appriciated !!

Thanks in advance !!

$subject = 'Mobile App Activation link';
$activation_url = 'mobileappname://accesstoken#w34rdgtsrt5v6m;
$activation_link = '<a href="' . $activation_url . '" title="Verify">' . $activation_url . '</a>';      

$mail_message = '<p>Thank you for signing up with us!</p>';
$mail_message .= '<p>Please click the verification link in order to complete the signup process.</p>';
$mail_message .= '<p>Verification Link: ' . $activation_link . '</p>';

add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html";' ) );
add_filter( 'wp_mail_from_name', 'mysite_from_name' );
add_filter( 'wp_mail_from', 'mysite_from_email' );

$res = wp_mail( $user_email, $subject, $mail_message );

Email content's source through Firebug looks like this: (href="" is striped out)

<a title="Verify" target="_blank">mobileappname://accesstoken#fs2fmhsf4nsv94s</a>
  • Try using escaping forward slash as following $activation_url = 'mobileappname:\/\/accesstoken#w34rdgtsrt5v6m'; – Vinod Dalvi Jul 2 '13 at 11:30
  • @VinodDalvi No, its not working. Still strips out the href. This is the html being sent in email content when looked through firebug: <a title="Verify" target="_blank">mobileappname:\/\/accesstoken#fs2fmhsf4nsv94s</a> – Subharanjan Jul 2 '13 at 11:35
2

You are missing a single quote '

$activation_url = 'mobileappname://accesstoken#w34rdgtsrt5v6m;

should be...

$activation_url = 'mobileappname://accesstoken#w34rdgtsrt5v6m';

or (using double quotes)...

$activation_url = "mobileappname://accesstoken#w34rdgtsrt5v6m";

Update:

See this codex entry for more: http://codex.wordpress.org/Function_Reference/wp_mail

add_filter( 'wp_mail_content_type', 'set_html_content_type' );
wp_mail( 'me@example.net', 'The subject', '<p>The <em>HTML</em> message</p>' );
remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); // reset content-type to to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578

function set_html_content_type()
{
    return 'text/html';
}

Basically you need to remove the plain text filter and replace it with the text/html filter to properly parse the HTML content you are sending via e-mail.

  • My bad.. this single quote missed while pasting/editing the question here. This is Ok in my code though. Still this is not working. Any idea how can make this work ? – Subharanjan Jul 2 '13 at 12:57
  • 1
    Actually yes! I had this problem two weeks ago and it was because I forgot to change the html content type of the wp_mail_content_type filter. – Adam Jul 2 '13 at 13:02
  • I am already adding the content type filter before calling wp_mail. Now I have added the remove_filter as well. Still issue is there; strips out the herf :( Doesn't it support any type of urls in the href ? – Subharanjan Jul 2 '13 at 13:12
  • 1
    @Subharanjan This is happening because you are using custom protocol mobileappname:// in your url. Refer these links for more information updates.html5rocks.com/2011/06/… stackoverflow.com/questions/7087728/… – Vinod Dalvi Jul 2 '13 at 13:16
  • @Vinod: Thats correct !! I am using the custom protocol to open the mobile app directly instead of opening the link in the mobile browser. But the mail is stripping out the href url itself. When I send a mail from outlook/Thunderbird with the same link, it doesn't strip out the url. – Subharanjan Jul 2 '13 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.