wp_mail filtering a URL
-
I have successfully sent a lot of emails through wp_mail, but I have now ran into a weird issue concerning URL:s. The email is sent as a result of a scheduled single event, which is executed by a cron job on my server with WP cron disabled:
cd /home/username/public_html; /usr/local/bin/php -q wp-cron.php
A URL for a post is a part of the email content, and the problem is that it automatically gets re-written from
“https://mysite.com/assignments/2018/09/21/12371237/”
to
“https:/assignments/2018/09/21/12371237/”
somewhere between wp_mail() and my inbox. So basically “/mysite.com/” gets stripped from the URL. This occurs even when skipping get_permalink and hard coding the URL as “https://mysite.com/assignments/2018/09/21/12371237/”, so it is not a problem with get_permalink. The email contains HTML, but even when just executing the following simple example this occurs. The rest of the HTML turns out fine though, so it’s just the URL that gets messed with.
$postURL = get_permalink(15375225168281); $body = 'URL: ' . $postURL; $headers[] = 'From: Me <[email protected]>'; $headers[] = 'Content-Type: text/html; charset=UTF-8'; wp_mail('[email protected]', 'Titel', $body, $headers);
When I send this email from anywhere else on my site however, which is not the result of a cron job, I don’t have this problem. Any ideas why this happens?
- The topic ‘wp_mail filtering a URL’ is closed to new replies.