Sending HTML with variables!

the mail() function

Moderators: macek, egami, gesf

meanrat
New php-forum User
New php-forum User
Posts: 5
Joined: Wed Sep 07, 2005 2:02 am
Location: Netherlands

Sending HTML with variables!

Postby meanrat » Fri Sep 30, 2005 9:47 am

Hello People

Currently I am practising with a PHP Comment Form. So people can send an email to the webmaster. What the plan is is that the user receives a confirmation that his email has been sent. And second, the webmaster will get an email. Now, I want to get these emails in HTML format.

I figured out how to activate HTML emails without using PEAR. But when I start using variables in this email the email plain copies the variables as they are: "$first_name $last_name wrote this comment: $comment".

So, no comments, no names, no nothing.

I have the code, but the variables are mostly in dutch. Hopefully you can see past 'em.

Code: Select all

if (empty($errors)) {
      
      $body = "Bedankt voor je commentaar. Er wordt zo spoedig mogelijk contact met je opgenomen.";
      $email = $_POST['email'];
      $extra = "From: $email";
      $voornaam = $_POST['voornaam'];
      $achternaam = $_POST['achternaam'];
      $comment = $_POST['commentaar'];
      $message = '
      <html><head><title>Commentaar van $voornaam</title></head>
      <body>
      <p><b>$voornaam $achternaam</b> heeft het volgende over je website gezegd:<br />
      <i>$comment</i></body></html>';
      /* To send HTML mail, set the Content-type header. */
      $headers  = "MIME-Version: 1.0\n";
      $headers .= "Content-type: text/html; charset=iso-8859-1\n";

      /* Additional headers */
      $headers .= "From: $email\n";
      $titel = "Commentaar van $voornaam";
      
      mail ($email, 'A Title For the mail', $body, 'From: info@myvisions.nl');
      mail ('info@myvisions.nl', $titel, $message, $headers);
      
      echo '<p>Your comment has been sent!</p>';


I translated some...
Thanks for reading.

Maarten

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Sat Oct 01, 2005 7:42 pm

Make it like this (example):

Code: Select all

<?php

$message = '<html>
  <head>
     <title>Commentaar van ' . $voornaam . '</title>
  </head>
    <body>     
    <p>
    <b>' . $voornaam . ' ' . $achternaam . '</b> heeft het volgende over je website gezegd:
    <br />
    <i>' . $comment . '</i>
  </body>
</html>';

?>
Get it ?

meanrat
New php-forum User
New php-forum User
Posts: 5
Joined: Wed Sep 07, 2005 2:02 am
Location: Netherlands

Postby meanrat » Sun Oct 02, 2005 1:08 am

Yes i get it. Thanks!


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 2 guests