WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a plugin that sends an email:

$subject = 'New comment - '.$post_title;
    include(SUBSCRIBE_USER_BASE_DIR . '/email/message.php');
    $message = ob_get_clean();

    foreach($user_emails as $user_email){
        $to = $user_email;
        $send_mail = wp_mail( $to, $subject, $message );
            echo 'Mail sent';

My email message is this:

<img src="<?php echo SUBSCRIBE_USER_BASE_DIR . '/email/email_header.png'; ?>" width="600px" height="100px" />
<div>A new comment has been posted on MySite.</div>
<div><?php echo get_the_title($comment->comment_post_ID); ?>
<p><?php echo $comment->comment_content; ?></p>

Where SUBSCRIBE_USER_BASE_DIR is defined as:

define('SUBSCRIBE_USER_BASE_DIR', dirname(__FILE__));

This works fine except for the image not appearing. Instead it's an empty image placeholder.

I already define the email format prior in my plugin as follows:

function av_subscribe_format_email(){
    return "text/html";
add_filter( 'wp_mail_content_type', create_function('', 'return "text/html";' ) );

The format and image is also confirmed if I view the source of the resulting email:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><img src="/var/www/html/internal/wp-content/plugins/AV_-_Subscribe_User/email/email_header.png" width="600px" height="100px">

Yet the image still doesn't show.

I should also mention that I allowed Downloading of images in Outlook to view the email.

share|improve this question
up vote 1 down vote accepted

Ok, so I switched the image root path from

define('SUBSCRIBE_USER_BASE_DIR', dirname(__FILE__));


define('SUBSCRIBE_USER_BASE_URL',plugin_dir_url(__FILE__)); and this worked.

dirname(__FILE__) registers:

<img src="/var/www/html/internal/wp-content/plugins/AV_-_Subscribe_User/email/email_header.png"

Whereas the latter plugin_dir_url(__FILE__) outputs:

<img src="http://mysite.com/wp-content/plugins/AV_-_Subscribe_User/email/email_header.png"

I'm not 100% clear as to when to use which but I'm guessing that I would use dirname when I am operating within the site server.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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