-1

Possible Duplicate:
Php mail: how to send html?

I got my mail() with php working my emailmessage =

$email_bericht .= "
        <table border='0' width='40%'>
            <tr>
                  <td>Bedrijfsnaam</td>
                  <td>
                  ".$naam."
                  </td>
            </tr>
            <tr>
                  <td>Risicoadres</td>
                  <td>
                  ".$risicoadres."
                  </td>
            </tr>
            <tr>
                  <td>Adres</td>
                  <td>
                  ".$adres."
                  </td>
            </tr>
            <tr>
                  <td>Woonplaats</td>
                  <td>
                  ".$woonplaats."
                  </td>
            </tr>
            <tr>
                  <td>Relatienummer</td>
                  <td>
                  ".$relatienummer."
                  </td>
            </tr>
            <tr>
                  <td>Aanhef</td>
                  <td>
                  ".$aanhef."
                  </td>
            </tr>
            <tr>
                  <td>Contactpersoon</td>
                  <td>
                  ".$contactpersoon."
                  </td>
            </tr>
            <tr>
                  <td>mailadres</td>
                  <td>
                  ".$emailadres."
                  </td>
            </tr>
                  <td>Jaar</td>
                  <td>
                  ".$jaar."
                  </td>
            </tr>
        </table>";

In the email it shows :

        <table border='0' width='40%'>
            <tr>
                  <td>Bedrijfsnaam</td>
                  <td>
                  Bob
                  </td>
            </tr>
            <tr>
                  <td>Risicoadres</td>
                  <td>
                  Bobstreet 12
                  </td>
            </tr>
            <tr>
                  <td>Adres</td>
                  <td>
                  Bobstreet 12
                  </td>
            </tr>
            <tr>
                  <td>Woonplaats</td>
                  <td>
                  England
                  </td>
            </tr>
            <tr>
                  <td>Relatienummer</td>
                  <td>
                  123456
                  </td>
            </tr>
            <tr>
                  <td>Aanhef</td>
                  <td>
                  Dear guy
                  </td>
            </tr>
            <tr>
                  <td>Contactpersoon</td>
                  <td>
                  Bob
                  </td>
            </tr>
            <tr>
                  <td>mailadres</td>
                  <td>
                  BOB@bobbv.nl
                  </td>
            </tr>
                  <td>Jaar</td>
                  <td>
                  2028
                  </td>
            </tr>
        </table>";

My mail() =

mail($email_naar, $email_onderwerp, $email_bericht);
mail($emailadres, $email_onderwerp, $email_bericht);

It shows all the table/tr's/td's etc in the mail that has been send to the email adress any way to solve this problem do i need to use a html tag or something?

Community
  • 1
  • 1
sjeggiepop
  • 69
  • 7

4 Answers4

4

if send mail without header information it will take table,tr,td as string you need to in include

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '. $sendermail . "\r\n";
mail($to, $subject, $message, $headers)
nickle
  • 4,636
  • 1
  • 13
  • 11
1

You need to set

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

And then:

mail($email_naar, $email_onderwerp, $email_bericht, $headers);
1

You need to add headers to your mail() call (fourth parameter) Specifically for your purpose you need (with relevant charset) 'Content-type: text/html; charset=iso-8859-1';

Please, refer to http://php.net/manual/en/function.mail.php to learn more about sending headers in e-mail. You'll need some of them, like 'Reply-To' and some others

Alexander Taver
  • 474
  • 3
  • 4
1

I think mail() function sending mail as a plain text where HTML part will not be rendered.

Here is the sample program to send HTML email. (copy and paste from php.net)

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </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 .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

Code source from http://php.net/manual/en/function.mail.php

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70