PirateBagel Posted March 22, 2007 Share Posted March 22, 2007 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/ Share on other sites More sharing options...
UTAlan Posted March 22, 2007 Share Posted March 22, 2007 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-213015 Share on other sites More sharing options...
Unholy Prayer Posted March 22, 2007 Share Posted March 22, 2007 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. Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-213019 Share on other sites More sharing options...
PirateBagel Posted March 28, 2007 Author Share Posted March 28, 2007 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 Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-216967 Share on other sites More sharing options...
PirateBagel Posted March 28, 2007 Author Share Posted March 28, 2007 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. Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217039 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 Anyone? I can't seem to get this working. Ill donate $10 right away if I can get a little help Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217139 Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217144 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 proposalconfig.inc <? $headers&#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 Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217161 Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217167 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 I did see that, I'm workin on fixin it right now. This script was hacked down from another one I was using, I always end up with shit like this when I do that. Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217169 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217182 Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 // 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217185 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 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. Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217192 Share on other sites More sharing options...
Waldir Posted March 29, 2007 Share Posted March 29, 2007 $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); Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217193 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 $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 this place rocks Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217197 Share on other sites More sharing options...
Waldir Posted March 29, 2007 Share Posted March 29, 2007 from what i can see this is what you have for email : $email = "..."; Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217199 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 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? Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217200 Share on other sites More sharing options...
Waldir Posted March 29, 2007 Share Posted March 29, 2007 chenge: $from .= 'From: From: Online Form''.$eol; to $from .= 'From: From: Online Form'.$eol; Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217201 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 chenge: $from .= 'From: From: Online Form''.$eol; to $from .= 'From: From: Online Form'.$eol; it all works now, thank you!!! Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217202 Share on other sites More sharing options...
Waldir Posted March 29, 2007 Share Posted March 29, 2007 no problem, make sure you mark it solved. Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217203 Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 // 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217206 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 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 https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217207 Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 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. Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217210 Share on other sites More sharing options...
PirateBagel Posted March 29, 2007 Author Share Posted March 29, 2007 That worked, thank you all very much. Ill be donating as soon as cash is in my paypal Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217216 Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 No problem. Stick around, this place is where I started learning (behind the scenes), and continue to learn from. It's a great source! Link to comment https://forums.phpfreaks.com/topic/43883-solved-including-html-and-css-into-a-form-email/#findComment-217219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.