Jump to content

Email Form HTML formatting


Visioncommunications

Recommended Posts

I created an email form for a website that I built.  When it sends the email which is supposed to be formatted in HTML.  However, my email client (yahoo which supports html) shows me the html instead of formatting it.  Where did I go wrong.  Below is a copy of the php.  I changed the email address for privacy.  I appreciate any help

 

 

<?
$subject="Web Query from ".$_GET['Name'];
$headers="From: ".$_GET['E-mail'];
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("[email protected]", $subject, "
<html>
<head>
  <title>Query From Web</title>
  </Head>
  <body>
  
  <br>
  ".$_GET['Name']."</br>".$_GET['Company']."</br>".$_GET['Street_Address']."</br>".$_GET['City,_State,_Zip']."</br>".$_GET['Phone']."</br>".$_GET['E-mail']."</br>".$_GET['Message']."
  </body>
  </html>" , $headers);
  echo ("Thank you for contacting TRCI!");
  ?>/code]

Link to comment
https://forums.phpfreaks.com/topic/186060-email-form-html-formatting/
Share on other sites

you are not separating your headers .. as you have them right now, $headers looks like this:

 

$headers="From: [email protected]: text/html; charset=iso-8859-1";

 

more or less, is how the mail server will see your headers .. it can't tell what from what.

 

you need to create breaks:

 

$headers  = "From: " . $_GET['E-mail'] . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"';

 

and for the sake of clarity, create a variable outside of the mail function that will contain your message/body, instead of having all your HTML right there inside the mail function:

 

<?php
$body = <<<BODY
<html>
	<head>
		<title>Query From Web</title>
	</head>
	<body>
		<br />
		{$_GET['Name']}
		<br />
		{$_GET['Company']}
		<br />
		{$_GET['Street_Address']}
		<br />
		{$_GET['City,_State,_Zip']}
		<br />
		{$_GET['Phone']}
		<br />
		{$_GET['E-mail']}
		<br />
		{$_GET['Message']}
	</body>
</html>
BODY;
?>

 

then:

 

mail ('[email protected]', $subject, $body, $headers);

 

much cleaner.

Mr. Marcus, I appreciate your help.  I tried the first way that you said and I got the same ol' results.  So then I tried the second way using a variable. This is what was then sent to me.

 

 

  <html>

        <head>

            <title>Query From Web</title>

        </head>

        <body>

            <br />

            asdfasdgsdg

            <br />

            Vision Communications

            <br />

            1234 mulberry lane

            <br />

            not a town, IN 46577

            <br />

            234-567-8901

            <br />

            [email protected]

            <br />

            I like to eat bannanas

        </body>

    </html>

 

 

The whole php code that I used is

 

<?php
$body = <<<BODY
<html>
	<head>
		<title>Query From Web</title>
	</head>
	<body>
		<br />
		{$_GET['Name']}
		<br />
		{$_GET['Company']}
		<br />
		{$_GET['Street_Address']}
		<br />
		{$_GET['City,_State,_Zip']}
		<br />
		{$_GET['Phone']}
		<br />
		{$_GET['E-mail']}
		<br />
		{$_GET['Message']}
	</body>
</html>
BODY;

mail ('[email protected]', $subject, $body, $headers);
?>
/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.