Jump to content

[SOLVED] Including html and css into a form email


PirateBagel

Recommended Posts

Alright, so on my website I have a form. Customers can fill it out and an email is sent to a specified adress, blah blah blah.

 

Now, I need to make a form that does the same thing, but I need to include images and CSS into the body of the email. So far I have not figured out how to do this.

 

The portion of my script that controls whats in the email is as follows:

$msg2 = "
Name: $name

Email: $email

Phone: $phone

Adress: $adress

City/State: $citystate

Zip Code: $zipcode

Services?: $pruning
$spray_fertilization
$removal_stumpgrinding
$planting
$other
$serviceother

Outline of Work: $outline

Comments?: $comments
";

 

Simple and easy for just a text based email. When I try to add HTML the whole script just goes kaputt.

 

I know its gotta be simple, any help is appreciated. If I need to post any more of the code just let me know, thanks!

 

Bagel

Make sure you are setting the headers correctly for an HTML email:

 

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

 

Where would I add this? Would it need to be defined within the message?

 

 

If I went about it the other way with an external style sheet, could I use .php or .css instead? How would I add the php variables? would they go in the external file?

 

If I do get help for this I will be donating to the site, you guys have helped me before and I will be making money off of this :D

You could try using <link rel=stylesheet href='url'> in your email message and then include a tpl file of the form's body with the css classes incorporated into it.

When I try this I just get <link rel=stylesheet href='proposalmail.php'> in an email.

 

Look for the portion of your script that has to do with sending the email. Most likely something like "mail($to, $subject, $body, $headers)".

 

Then look to see if there is already something in your code declaring the variable $headers. If not, right above the mail() function, add this:

 

// To send HTML mail, the Content-type header must be set
$headers&#160; = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

It would be a good idea to show us your mail(); function and any variables that seem to be used by it.

proposalconfig.inc

<?
$headers&#38;#160; = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$subject = "Proposal Form";


$msg2 = "
test<br>test
";
?>

 

proposalback.php

<?
  include('proposalconfig.inc');

if ($_SERVER['REQUEST_METHOD'] == "POST") {




   mail("$email", "$headers $subject", "$msg2", "From: Online Estimate Form 

\nReply-To: $email");

//if all correct redirect.

header("location: .../contactthanks.php");

     } else {
        echo "<br><center>$finishedtext</center><br>";
     }


include("proposalform.php");
?>

 

I removed all non-relevant code

 

And there is nothing relative in proposalform.php.

 

I'm pretty sure I followed your instructions correctly, but I still get

test<br>test

in the email.

 

Thank you very much for the help though :D

 

Somehow the headers messed up in my last post. Should be:

 

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

 

Don't know much about mail(), but

 

mail("$email", "$headers $subject", "$msg2", "From: Online Estimate Form\nReply-To: $email");

 

Just doesn't look right. "$headers $subject"

 

They should all be separated from what I know. Something more like

 

mail("$email", "$subject", "$msg2", "From: Online Estimate Form \nReply-To: $email", "$headers");

 

(This is where a more experienced coder needs to step in)

I replaced that line, Everything seems to be in order, but it is still not working :(

 

heres the updated files:

proposalback.php

<?
  include('proposalconfig.inc');

if ($_SERVER['REQUEST_METHOD'] == "POST") {

mail("$email", "$subject", "$msg2", "From: Online Form", "Reply-To: $email", "$headers");

//if all correct redirect.

header("location: http://017b5a6.netsolhost.com/contactthanks.php");

     } else {
        echo "<br><center>$finishedtext</center><br>";
     }
  

include("proposalform.php");
?>

 

proposalconfig.php

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

$subject = "Proposal Form";

$email = "...";

$msg2 = "
test<br>test
";
?>

If anyone can help with this it will be much appreciated and I will donate $10 to the board

// 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";
$headers .= 'From: Online Form' . "\r\n";
$headers .= 'Reply-To: $email' . "\r\n";

 

And then maybe:

 

mail("$email", "$subject", "$msg2", "$headers");

 

I don't know, worth a shot right?

Im trying that now, there is something kind of weird though. when I just have $email in the title it doesnt send me an email (i have it defined in config.inc as $email = "[email protected]";).

It does seem to work when I replace $email with my actual adress though.

 

$eol = "\r\n";
$from = "Content-Type: text/html; charset=iso-8859-1".$eol;
$from .= "Content-Transfer-Encoding: 8bit".$eol;
$from .= 'From: From: Online Form''.$eol;   
mail($email,$subject,$msg2,$from);

 

This works!! Thank you!!

 

...but... it still does not email to me if I just leave $email in the mail(), I need to fix this because this form needs to be emailed to hundreds of people.

 

I will be donating to the board too :D this place rocks

from what i can see this is what you have for email : $email = "...";

Thats because I didn't need to advertise my work email to everyone

 

Now im getting

 

Parse error: syntax error, unexpected T_STRING in /data/12/1/9/96/1172911/user/1246821/htdocs/forms/proposalconfig.php on line 7

 

on proposalconfig.inc

<?
$email  = "[email protected]";
$eol = "\r\n";
$from = "Content-Type: text/html; charset=iso-8859-1".$eol;
$from .= "Content-Transfer-Encoding: 8bit".$eol;
$from .= 'From: From: Online Form''.$eol; 
$subject  = "Proposal Form";


$msg2 = "
test<br>test
";
?>

Line 7 is the $subject, how the hell is it failing on that?

// 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";
$headers .= 'From: Online Form' . "\r\n";
$headers .= 'Reply-To: $email' . "\r\n";

 

And then maybe:

 

mail("$email", "$subject", "$msg2", "$headers");

 

I don't know, worth a shot right?

 

Just as a follow- up, I tried this, and it worked 100%.

Yeah, I tried that too, the HTML and CSS worked for me, but the $email didn't. Thanks for the help.

 

 

The email it sends doesnt have my correct domain name on it, instead i get

(whatever $from is)@vux.bos.netsolhost.com

 

Anyway I can fix that? or am I just going to have to deal w/ it?

Maybe with ini_set()?

 

I don't know, maybe try getting rid of -

 

$from .= 'From: From: Online Form''.$eol;

 

and replace it with -

 

ini_set("sendmail_from","[email protected]");

 

Or if you have access to your php.ini you can change 'sendmail_from' manually.

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.