0

I'm making a mail function which could send some text with a picture, it works fine with plain text, but after adding the img code, what recipients got was still plain text. The image was located in the root directory.

Code below:

<form method="POST">
<input name="submit" type="submit"  value="send!"/>
</form>
<?php 
if(isset($_POST['submit'])){
$to="[email protected]";
// subject
$subject = 'test05';

// message
$message = "
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
<img id='cat' width='208px' src='/cat.jpg'>
  </table>
</body>
</html>

";

// 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";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'Reply-To: [email protected]' . "\r\n";

// $headers .= 'From: Panpan <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";


// mail($to, $subject, $message, $headers);
      if (mail($to, $subject, $message, $headers)) {
        // echo "Mail was sent! Great!";
        echo $message;
      } 
      else {
        echo "Mission Failed";
      }

}
?>
1
  • 1
    The image needs to be the absolute path, not relative path Commented Feb 11, 2016 at 16:52

1 Answer 1

1

What would a mail client know to do with this?:

/cat.jpg

Is cat.jpg in the root of gmail.com? Is it in the root of an Outlook application? The mail client simply has no way of knowing where your image is because you didn't tell it where to look.

Use a fully-qualified URL:

http://somedomain.com/cat.jpg

Note also that some mail clients may still ignore this, maybe depending on user settings. Linking to resources in mail is an old spammer trick for tracking whether or not messages are being opened/read. Embedding the image as a resource in the message is often a better approach.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.