I’m trying to write a simple plugin using wp_schedule_event to send emails.
The first example below works fine, but in the second (where I try to include a url within the email) nothing happens.
Why? And how can I include a link within the email?
EXAMPLE 1
add_action('init', function() {
if ( !wp_next_scheduled('my_email') ) {
wp_schedule_event(time(), 'hourly', 'my_email' );
}
});
add_action('my_email', function() {
$body = "A text message including a link.";
wp_mail('myaddress@gmail.com', 'Email Subject', $body );
});
EXAMPLE 2
add_action('init', function() {
if ( !wp_next_scheduled('my_email') ) {
wp_schedule_event(time(), 'hourly', 'my_email' );
}
});
add_action('my_email', function() {
$my_url = site_url('/resources/links/', 'http');
$link ="<a href=" . $my_url . ">link</a>";
$body = "A text message including a $link.";
wp_mail('myaddress@gmail.com', 'Email Subject', $body );
});
I guess the problem is just a syntax error..
it should read:
but in this way it will just print out the html as text. you must also add headers to tell that it’s an html email.