1

I'm using wp_mail() to send e-mail from our website. However, we would like to include a .gif file on the body of our message. Here's my code, but it's not working.

$to = $contact['Email'];
$from = 'test@test.com';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: Testing Mail <'.$from .'>'. "\r\n";

$subject = "Subject Text";
$customer_name = $contact['FirstName'];

$message = '<html><body>';
$message .="<p>message!</p>";
$message .= "<p>message </p>";
$message .= "<img src='img/signature.gif'>";

$message .= '</body></html>';
wp_mail($to, $subject, $message, $headers);
2

You have to provide the absolute path for your included image, as the receiver of the email does not have a file "signature.gif" in a folder "img" (that's where the client is going to search it)

Replace

$message .= "<img src='img/signature.gif'>";

with

$message .= "<img src='http://yourwebsite.com/PATH/TO/img/signature.gif'>";

Where yourwebsite.com is your website's domain followed by the complete path.

Depending on where you added your code, you can access a WordPress function, to add the domain dynamically. This is useful if you have to move your website to another domain (for a staging/developing enviroment for example). Have a look at get_site_url().

You could use it like this:

$message .= "<img src='" . get_site_url() . "/PATH/TO/img/signature.gif'>";
0

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.