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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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  = '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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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  = "adams@arborpronw.com";
$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?

Link to comment
Share on other sites

// 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%.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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","adam@blah.net");

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.