cmb Posted October 15, 2012 Share Posted October 15, 2012 Im trying to send a html email when i do this locally using mercury mail it works fine. Once i uploaded it and tried sending a email to gmail and yahoo it didn't work this is my php code <?php $from = $_REQUEST['from']; $to = $_REQUEST['to']; $bcc = $_REQUEST['bcc']; $subject = $_REQUEST['subject']; $message = $_REQUEST['msg']; // To send the HTML mail we need to set the Content-type header. $headers = 'From: ' . $from . "\nReply-To: ". $from ."\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'Bcc:' . $bcc . "\r\n"; // now lets send the email. mail($to, $subject, $message, $headers); print json_encode( "Message has been sent....!"); ?> this is the html i was trying to send (i also tried something simpler and that didn't work either) <html> <body style="background-color: #000;"> <table> <tr> <td id="pinkpanthers" style="border: 2px solid #393;padding: 40px 40px; width: 100px;border-radius: 25px; color: #000; background-color: #393;font-size: x-large;" style="border: 2px solid #393;padding: 40px 40px; width: 100px;border-radius: 25px; color: #000; background-color: #393;font-size: x-large;"><a href="http://www.photosbychristian.com/pinkpanthers/index.php" style="text-decoration:none;color: #fff;">Pink<br />Panthers</a></td> <td id="gbsa" style="border: 2px solid #393;padding: 40px 40px; width: 100px;border-radius: 25px; color: #000; background-color: #393;font-size: x-large;"><a href="http://www.photosbychristian.com/gbsa/index.php" style="text-decoration:none;color: #fff;">GBSA</a></td> <td id="elite" style="border: 2px solid #393;padding: 40px 40px; width: 100px;border-radius: 25px; color: #000; background-color: #393;font-size: x-large;"><a href="http://www.photosbychristian.com/elite/index.php" style="text-decoration:none;color: #fff;">Elite</a></td> <td id="THS" style="border: 2px solid #393;padding: 40px 40px; width: 100px;border-radius: 25px; color: #000; background-color: #393;font-size: x-large;"><a href="http://www.photosbychristian.com/THS/index.php" style="text-decoration:none;color: #fff;">THS</a></td> <td id="HDR" style="border: 2px solid #393;padding: 40px 40px; width: 100px;border-radius: 25px; color: #000; background-color: #393;font-size: x-large;"><a href="#" style="text-decoration:none;color: #fff;">HDR</a></td> <td id="family" style="border: 2px solid #393;padding: 40px 40px; width: 100px;border-radius: 25px; color: #000; background-color: #393;font-size: x-large;"><a href="#" style="text-decoration:none;color: #fff;">Family</a></td> </tr> <tr> <td colspan="6"> <p style="color: #fff; text-align:center;">Text will go here</p> </td> </tr> </table> </body> </html> this is the headers from gmail Delivered-To: cmbswim@gmail.com Received: by 10.194.21.41 with SMTP id s9csp621144wje; Sun, 14 Oct 2012 18:02:53 -0700 (PDT) Received: by 10.66.86.42 with SMTP id m10mr29016349paz.3.1350262972933; Sun, 14 Oct 2012 18:02:52 -0700 (PDT) Return-Path: <christianbasse@p3nlhg198.shr.prod.phx3.secureserver.net> Received: from p3nlsmtp20.shr.prod.phx3.secureserver.net (p3nlsmtp20.shr.prod.phx3.secureserver.net. [72.167.234.245]) by mx.google.com with ESMTP id bc7si3012631pab.65.2012.10.14.18.02.52; Sun, 14 Oct 2012 18:02:52 -0700 (PDT) Received-SPF: pass (google.com: domain of christianbasse@p3nlhg198.shr.prod.phx3.secureserver.net designates 72.167.234.245 as permitted sender) client-ip=72.167.234.245; Authentication-Results: mx.google.com; spf=pass (google.com: domain of christianbasse@p3nlhg198.shr.prod.phx3.secureserver.net designates 72.167.234.245 as permitted sender) smtp.mail=christianbasse@p3nlhg198.shr.prod.phx3.secureserver.net Received: from p3nlhg198.shr.prod.phx3.secureserver.net ([97.74.24.198]) by p3nlsmtp20.shr.prod.phx3.secureserver.net with id BD2n1k0044GSV4Z01D2nXS; Sun, 14 Oct 2012 18:02:52 -0700 Received: from p3nlhg198.shr.prod.phx3.secureserver.net (localhost [127.0.0.1]) by p3nlhg198.shr.prod.phx3.secureserver.net (8.14.4/8.12.11) with ESMTP id q9F12b5Q001356 for <cmbswim@gmail.com>; Sun, 14 Oct 2012 18:02:42 -0700 Received: (from christianbasse@localhost) by p3nlhg198.shr.prod.phx3.secureserver.net (8.14.4/8.14.4/Submit) id q9F12b7P001352; Sun, 14 Oct 2012 18:02:37 -0700 Date: Sun, 14 Oct 2012 18:02:37 -0700 Message-Id: <201210150102.q9F12b7P001352@p3nlhg198.shr.prod.phx3.secureserver.net> To: cmbswim@gmail.com Subject: Sample From: christian@photosbychristian.com Reply-To: christian@photosbychristian.com MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 Quote Link to comment https://forums.phpfreaks.com/topic/269466-html-email/ Share on other sites More sharing options...
DavidAM Posted October 15, 2012 Share Posted October 15, 2012 ... it didn't work What exactly does that mean? Did the message NOT get sent? Did it get sent and land in the "Junk Mail" folder? Did it get sent, but the HTML is missing? Did it get sent but the message looks wrong? ... ? ? ? Add an IF test to see if the mail() function succeeds // now lets send the email. if (mail($to, $subject, $message, $headers)) print json_encode( "Message has been sent....!"); else print json_encode("Failed to send message"); Your server may not be configured correctly for sending emails. Have you ever used the mail() function on this server successfully (for a plain text message)? this is the html i was trying to send (i also tried something simpler and that didn't work either) ... I don't see where you are including any HTML in the $message variable, unless you typed all of that into the form? We need more information if we are to have any chance at helping you. The From: header needs to be an email address that the server is authorized to send mail for. Typically, this is an address related to your website; definitely not the address of the user filling out the form (use the Reply-To: header for that). Be consistent with the end-of-line sequences in the headers. After the From: header you have \n, it should be \r\n (like all of the rest). Quote Link to comment https://forums.phpfreaks.com/topic/269466-html-email/#findComment-1385231 Share on other sites More sharing options...
cmb Posted October 15, 2012 Author Share Posted October 15, 2012 the email sent fine and it showed up in my imbox but it was just a simple table with no css showing and the links not working the message is coming from a form as is bcc, to, and subject i changed the headers to look like this $headers = "From: Christian Basse <christian@photosbychristian.com>\r\n"; $headers .= "Reply-To: ". $from ."\r\n"; $headers .='MIME-Version: 1.0' . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; $headers .= "Bcc:" . $bcc . "\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/269466-html-email/#findComment-1385233 Share on other sites More sharing options...
DavidAM Posted October 15, 2012 Share Posted October 15, 2012 See, to me that is not "it didn't work". That is "the inline styling isn't working". Keep in mind, if you are reading the emails with a browser, the HTML in your message is being placed inside of the HTML for the mail page. So the BODY tag you supplied is inside another BODY tag. That is invalid HTML and may cause rendering problems. However, you can't really leave it out, can you? I mean, if the user uses a mail client instead of a browser, I'm guessing that stuff needs to be there. I have not experimented with it a lot, so I don't know the "correct" way to handle this. I typically include the full HTML, HEAD, BODY, etc. Mostly because I include the TITLE (in the HEAD) for the Subject when displayed in a mail client. That being said, your BODY tag is probably being ignored, which means that background-color is being ignored. I would move the background-color down to the TABLE tag --- or wrap everything inside your BODY in a DIV and put the background on the DIV. The last two links don't have an address, it is just "#"; so they won't go anywhere. You might try putting the CSS in a STYLE sheet in the HEAD or the BODY, instead of inline. I think it looks cleaner, but I don't know how widely supported it is. It seems most people recommend inline styling for HTML emails. Quote Link to comment https://forums.phpfreaks.com/topic/269466-html-email/#findComment-1385235 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.