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="example@outlook.com";
// 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 <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'Reply-To: example@outlook.com' . "\r\n";

// $headers .= 'From: Panpan <general@panpan.tokyo>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";


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

}
?>
ryanpika
  • 151
  • 3
  • 13

1 Answers1

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.

Community
  • 1
  • 1
David
  • 208,112
  • 36
  • 198
  • 279