TeddyKiller Posted March 23, 2010 Share Posted March 23, 2010 Hello. For example.. This will send a basic email. $send = mail("To address", "Subject" , "My message.", "From address"); How can I send an email which.. is all fancy with HTML, CSS and images etc, which are not attachments? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/ Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 You'll need to define the MIMETYPE before the client would even think to parse sgml/css. $header = "From: Foobar <[email protected]> " . "\r\n"; $header .= 'MIME-Version: 1.0' . "\n"; $header .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; Then that should work. Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030619 Share on other sites More sharing options...
TeddyKiller Posted March 23, 2010 Author Share Posted March 23, 2010 So would that allow me to add html and images. eg: $message = "<h1>Hello</h1><br /><img src="myimg.jpg" /><br /><h2>Goodbye</h2>"; How would I include it with in with my little $send. Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030622 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 You can't. An image isn't text data, You must include it from a remote server. Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030624 Share on other sites More sharing options...
TeddyKiller Posted March 23, 2010 Author Share Posted March 23, 2010 So.. <img src="http://mysite.com/myimg.jpg" \> ?? Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030626 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 <img src="http://mysite.com/myimg.jpg" /> Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030627 Share on other sites More sharing options...
TeddyKiller Posted March 23, 2010 Author Share Posted March 23, 2010 Same difference.. How would I include the header in? Would it simply be.. $header = "From: Foobar <[email protected]> " . "\r\n"; $header .= 'MIME-Version: 1.0' . "\n"; $header .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $send = mail("To address", "Subject" , "My message.", "$header"); Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030629 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 Yes, that should suffice as the order is $to, $subject, $message, $header. I'd replace the FROM part with your servername in it, so clients don't assume it's spam etc. Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030632 Share on other sites More sharing options...
TeddyKiller Posted March 23, 2010 Author Share Posted March 23, 2010 How would I be able to send emails to multiple recipents? $to = "mail1, mail2" $send = mail($to, "Subject" , "My message.", "$header"); Is that right? What do you mean replacing the FROM with my server name in it? Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030638 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 The FROM portion (name <[email protected]>) needs to be filled out correctly for the client to authenticate that the e-mail is real. Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030641 Share on other sites More sharing options...
TeddyKiller Posted March 23, 2010 Author Share Posted March 23, 2010 Thanks. However.. $message .= "<div id=\"header\" style=\"background:url(http://www.horble.com/ima/hdrtit.jpg) no-repeat; width:90%; height:40px; margin: 0 auto;\">"; It doesn't get a background image? Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030670 Share on other sites More sharing options...
TeddyKiller Posted March 23, 2010 Author Share Posted March 23, 2010 I changed it to image tags, works fine. $header = "From: $name <[email protected]> " . "\r\n"; It still comes up in junk? how can I prevent this. (For me it doesn't I marked it as safe) Quote Link to comment https://forums.phpfreaks.com/topic/196256-html-emails-with-images-and-css/#findComment-1030680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.