Sending HTML with variables!

the mail() function

Moderators: egami, macek, gesf

Post Reply

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>
		<p><b>$voornaam $achternaam</b> heeft het volgende over je website gezegd:<br />
		/* 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:');
		mail ('', $titel, $message, $headers);
		echo '<p>Your comment has been sent!</p>';
I translated some...
Thanks for reading.


User avatar
Posts: 1716
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Sat Oct 01, 2005 7:42 pm

Make it like this (example):

Code: Select all


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

Get it ?
Gonçalo "gesf" Fontoura | |


Sun Oct 02, 2005 1:08 am

Yes i get it. Thanks!

Post Reply