-3

I've tried this code but i didn't work

Code in index.php

<form action='send.php' method='post'>
    Sender: <input type='text' name='sender'> </ br>
    Message: textarea name='message'></textarea>
    <input type='submit' name='submit' value='Send' />
</form>

Code in send.php

$to = "my_email@yahoo.com";

$sender = $_POST['sender'];

$message = $_POST['message'];

$design_message = "<div style='background-color: red'>" . $message . "</div>";

if(isset($_POST['submit'])){

 mail($to, "Test", $design_message, "From: " . $sender);

}

The message will be send to my email but it doesn't have any design

xdazz
  • 158,678
  • 38
  • 247
  • 274

1 Answers1

2

To send an email that contains HTML content you have to add the following headers:

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

You can send them here

mail($to, $subject, $message, $headers);
                              ^

Source

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95