SalientAnimal Posted October 30, 2012 Share Posted October 30, 2012 Hi All, Can anyone suggest where I can start looking to on how to create a HTL Rich E-Mail that is generated from a PHP form? I have done various searchs on Google and I haven't been able to find anything that seems to work. Basically, I want the form infor to be psoted to the MySQL database, but at the same time to send a HTML Rich E-mail to the used who completed the form. I have the normal e-mail and writing to the database working, I just want to spice it up now... Any help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/ Share on other sites More sharing options...
White_Lily Posted October 30, 2012 Share Posted October 30, 2012 $regPassword = sha1($regPassword); $id = uniqid(); $register = insert("members", "name, email, username, password, user_level, id, ban", "'$regName', '$email', '$regUsername', '$regPassword', 1, '$id', 0"); if($register){ $newsTitle = "New member registered!"; $cont = $regUsername." has just joined Fusion Forums!<br>"; $cont.= "Check out his/her profile:<br><br>"; $cont.= "View Profile"; $newsCont = $cont; $newMem = insert("news", "news_title, news_content, username", "'$newsTitle', '$newsCont', '$regUsername'"); if($newMem){ $to = $email; $subject = "Fusion Forums - Account Confirmation"; $message = "Hello! You have recently registered to Fusion Forum's.<br><br>"; $message.= "This is a confirmation email, below you will find your account details along with a Unique ID.<br><br>"; $message.= "In order to activate your account you must first enter the ID into the text field that follows the link at the end of this email. Your details are as follows:<br><br>"; $message.= "<table>"; $message.= "<tr>"; $message.= "<td><strong>Name:</strong></td>"; $message.= "<td></td>"; $message.= "<td>".$regName."</td>"; $message.= "<tr>"; $message.= "<tr>"; $message.= "<td><strong>Email:</strong></td>"; $message.= "<td></td>"; $message.= "<td>".$email."</td>"; $message.= "<tr>"; $message.= "<tr>"; $message.= "<td><strong>Username:</strong></td>"; $message.= "<td></td>"; $message.= "<td>".$regUsername."</td>"; $message.= "<tr>"; $message.= "<tr>"; $message.= "<td><strong>Unique ID:</strong></td>"; $message.= "<td></td>"; $message.= "<td>".$id."</td>"; $message.= "<tr>"; $message.= "</table><br><br>"; $message.= "Please follow this link in order to activate your account (opens in your default browser):<br>"; $message.= "<a href='http://www.janedealsart.co.uk/activate.php?id=".$id."'>Activate Account</a>"; $from = "noreply@janedealsart.co.uk"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers.= "From: ".$from; mail($to, $subject, $message, $headers); $done = "You have successfully registered to Fusion Fourm's.<br>"; $done.= "We have sent you an email with a confirmation code on it,"; $done.= " when you go to confirm your account you will need this code in order to be able to access the forum's."; $msg2 .= $done; }else{ $msg3 .= "Sorry, we could not register your account details, if this persists contact the webmaster. "; } }else{ $msg3 .= "Sorry, we could not register your account details, if this persists contact the webmaster. "; } That should work, it writes the users details to the database, enters some content into a news feed, then sends the user who registered an email with their details. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388748 Share on other sites More sharing options...
White_Lily Posted October 30, 2012 Share Posted October 30, 2012 You could probably put all those $message variables and values inside a different file and just include there instead, make it look a bit nicer. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388780 Share on other sites More sharing options...
SalientAnimal Posted October 31, 2012 Author Share Posted October 31, 2012 Cool thanks, I am going to work on this and then I will shout if I need more help . One thing that is not in there is what I would need to do if I wanted to add images into the mail. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388954 Share on other sites More sharing options...
White_Lily Posted October 31, 2012 Share Posted October 31, 2012 $message.= '<img src="images/filename.jpg" alt="name/description of image" />'; Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388961 Share on other sites More sharing options...
PFMaBiSmAd Posted October 31, 2012 Share Posted October 31, 2012 If you put any kind of link in the email, it must be a fully qualified (absolute) url - http://domain.com/path/file.ext Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388963 Share on other sites More sharing options...
SalientAnimal Posted October 31, 2012 Author Share Posted October 31, 2012 Ok, thats how I had it, but I just realsied that I was being a bit of an idiot and I tried adding the image to the subject tag. And of coarse this won't display an image. So basic HTML/PHP coding from here on in. Thanks guys, I should be able to finifh this now. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388964 Share on other sites More sharing options...
White_Lily Posted October 31, 2012 Share Posted October 31, 2012 make sure you change email address variables as required as well. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388966 Share on other sites More sharing options...
SalientAnimal Posted October 31, 2012 Author Share Posted October 31, 2012 Yip, busy updating everything. Slowly working on it. Question though, can I have a CSS file in the script as well? Or do I have to format each part fot he message? Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1388978 Share on other sites More sharing options...
White_Lily Posted October 31, 2012 Share Posted October 31, 2012 Dont ask - try it all out see if you can get it to work. Hint: you can't use files. You need to use a tag. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1389000 Share on other sites More sharing options...
Muddy_Funster Posted October 31, 2012 Share Posted October 31, 2012 You are effectivly sending an html page as the message body, so you can bould it as you would any other html page. You shouldn't need much css for an email so I'd suggest sending the css as pard of the head rather than linking to it, but you can stick it in the head whichever way you like : $message = <<<HTML_MESSAGE <html> <head> <title></title> <!-- link to a css file --> <link rel="stylesheet" type="text/css" href="http://your_server.com/css/email_styles/filename.css" /> <!-- add a block of css to style the mail --> <style type="text/css"> .all_your_css{ goes:in here; } </style> </head> <body> <div class="all_your_css">Your Eail Content Goes Here</div> </body> </html> HTML_MESSAGE; Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1389004 Share on other sites More sharing options...
SalientAnimal Posted October 31, 2012 Author Share Posted October 31, 2012 My image isn't attaching :-\ $message.= "<body background='http://vmcedctr01/img/mail_bg_main.jpg' width='100%' height='100%'/><font face='Arial' size='2' color='black'>"; $message.= "Hi $_POST[owner]<br><br>"; $message.= "Thank you for placing an online order. Here is a summary of your order. Please keep this email as a reference if you wish to track your order.<br><br> Your order details are as follows:<br><br>"; $message.= "<table border=1 width='40%'>"; That's just the top part of the code. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1389011 Share on other sites More sharing options...
Muddy_Funster Posted October 31, 2012 Share Posted October 31, 2012 that url desn't resolve, I get server not found when trying to point my browser at it... Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1389030 Share on other sites More sharing options...
ignace Posted November 1, 2012 Share Posted November 1, 2012 All CSS has to be inline for an HTML e-mail. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1389237 Share on other sites More sharing options...
SalientAnimal Posted November 5, 2012 Author Share Posted November 5, 2012 The url won't resolve as it is an internal server. The server isn't available externally. This mails will all be internal. Still can't get the picture to attach. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390351 Share on other sites More sharing options...
White_Lily Posted November 5, 2012 Share Posted November 5, 2012 if http://www.example.com/images/file-name.png doesn't work, then try: echo '<img src="'.$_SERVER["DOCUMENT_ROOT"].'/images/file-name.png" />'; Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390353 Share on other sites More sharing options...
SalientAnimal Posted November 6, 2012 Author Share Posted November 6, 2012 Now I get this error when hitting submit: Parse error: syntax error, unexpected end of file in \htdocs\submit\submit_drc_portal.php on line 238 Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390493 Share on other sites More sharing options...
Muddy_Funster Posted November 6, 2012 Share Posted November 6, 2012 yeah, gonna need to see the code up to and including that line number. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390494 Share on other sites More sharing options...
SalientAnimal Posted November 6, 2012 Author Share Posted November 6, 2012 (edited) Here is the code. Keep in mind that: A big part of this forms the actual body of the message. The server won't resolve as it is an internal server that I am testing on first. Some of the message body has been removed due to confidentiaity. Line 238 is the clsoing php tag -> ?> and will now be line 95 with the confidentiality part of the message body removed. <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } if ( $_POST['owner'] == "Owner Name" ) { $to = "Owner@departmentname.co.za"; $from = 'csops@departmentname.co.za'; $subject = "New Request - Reference Number $_POST[reference]_$_POST[request_type]"; $message.= " <html> <body background='http://internalservername/img/mail_bg_main.jpg' alt='name/description of image' width='100%' height='100%'/><font face='Arial' size='2' color='black'> <table border='0' width='85%' background='http://internalservername/img/mail_bg.jpg' align='center'><font face='Arial' size='2' color='black'> <td> <table border='0' width='43%' align='center'> <td> <font face='Arial' size='2' color='black'>Hi $Name<br><br> Thank you for placing an online order with departmentname. Here is a summary of your order. Please keep this email as a reference if you wish to track your order.<br><br> Your order details are as follows:<br><br> <table border='' width='40%'><font face='Arial' size='2' color='black'> <tr> <td><strong><font face='Arial' size='2' color='black'>Order Number:</strong></td> <td></td> <td><font face='Arial' size='2' color='black'>.$orderNumber.</td> </tr> <tr> <td><strong><font face='Arial' size='2' color='black'>Order Date:</strong></td> <td></td> <td><font face='Arial' size='2' color='black'>.$orderDate.</td> </tr> </table><br><br> <table border='' width='100%'><font face='Arial' size='2' color='black'> <tr> <td width='25%'><font face='Arial' size='2' color='black'><strong>Deal Description</strong></td> <td width='25%'><font face='Arial' size='2' color='black'><strong>Quantity</strong></td> <td width='25%'><font face='Arial' size='2' color='black'><strong>Price</strong></td> <td width='25%' colspan='2'><font face='Arial' size='2' color='black'><strong>Amount</strong></td> </tr> <tr> <td width='25%'><font face='Arial' size='2' color='black'>$dealDescription</td> <td width='25%'><font face='Arial' size='2' color='black'>$quantity</td> <td width='25%'><font face='Arial' size='2' color='black'>$price</td> <td width='12.5%'><font face='Arial' size='2' color='black'>Total</td> <td width='12.5%'><font face='Arial' size='2' color='black'>$total</td> </tr> <table border='0' width='100%'><font face='Arial' size='2' color='black'> <tr> <td><font face='Arial' size='2' color='black'><strong>Returns Policy:</strong> You can cancel this order within two weeks after we have received it. You can return new, unopened items from a cancelled order within 2 weeks after they have been delivered to you. Items should be returned in their original packaging.<br> <br>Should you have any queries, do get in touch with our customer services team on: 0741 000 5555 or send us an email shoponline@departmentname.co.za<br> <br>Your new phone will be dispatched once all your details are confirmed.<br> <br>Look forward to welcoming you to the family!<br> <br>Best wishes,<br> <font color='CC0000'> departmentname South Africa</td> </tr> </table><br><br> </td> </table> </td> </table> </html>"; mail($to, $subject, $message, $from); ?> Edited November 6, 2012 by SalientAnimal Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390497 Share on other sites More sharing options...
Muddy_Funster Posted November 6, 2012 Share Posted November 6, 2012 well that's unfortunate. Basicly your error is coming from the fact that something before line xxx is not terminated properly, either a missing semi-colon or closing curly brace is the common cause of this. but if you are striping out lines (which I fully appreciate you're need to do), then that's going to make finding it a little difficult. Here is a suggestion that I think should help. when you are assigning multiple string lines to a variable then use a heredoc string block i.e. $message .= <<<MESSAGE_PT2 <html> <body background='http://internalservername/img/mail_bg_main.jpg' alt='name/description of image' width='100%' height='100%'/><font face='Arial' size='2' color='black'> <table border='0' width='85%' background='http://internalservername/img/mail_bg.jpg' align='center'><font face='Arial' size='2' color='black'> <td> <table border='0' width='43%' align='center'> <td> <font face='Arial' size='2' color='black'>Hi $Name<br><br> Thank you for placing an online order with departmentname. Here is a summary of your order. Please keep this email as a reference if you wish to track your order.<br><br> Your order details are as follows:<br><br> <table border='' width='40%'><font face='Arial' size='2' color='black'> <tr> <td><strong><font face='Arial' size='2' color='black'>Order Number:</strong></td> <td></td> <td><font face='Arial' size='2' color='black'>.$orderNumber.</td> </tr> <tr> <td><strong><font face='Arial' size='2' color='black'>Order Date:</strong></td> <td></td> <td><font face='Arial' size='2' color='black'>.$orderDate.</td> </tr> </table><br><br> <table border='' width='100%'><font face='Arial' size='2' color='black'> <tr> <td width='25%'><font face='Arial' size='2' color='black'><strong>Deal Description</strong></td> <td width='25%'><font face='Arial' size='2' color='black'><strong>Quantity</strong></td> <td width='25%'><font face='Arial' size='2' color='black'><strong>Price</strong></td> <td width='25%' colspan='2'><font face='Arial' size='2' color='black'><strong>Amount</strong></td> </tr> <tr> <td width='25%'><font face='Arial' size='2' color='black'>$dealDescription</td> <td width='25%'><font face='Arial' size='2' color='black'>$quantity</td> <td width='25%'><font face='Arial' size='2' color='black'>$price</td> <td width='12.5%'><font face='Arial' size='2' color='black'>Total</td> <td width='12.5%'><font face='Arial' size='2' color='black'>$total</td> </tr> <table border='0' width='100%'><font face='Arial' size='2' color='black'> <tr> <td><font face='Arial' size='2' color='black'><strong>Returns Policy:</strong> You can cancel this order within two weeks after we have received it. You can return new, unopened items from a cancelled order within 2 weeks after they have been delivered to you. Items should be returned in their original packaging.<br> <br>Should you have any queries, do get in touch with our customer services team on: 0741 000 5555 or send us an email shoponline@departmentname.co.za<br> <br>Your new phone will be dispatched once all your details are confirmed.<br> <br>Look forward to welcoming you to the family!<br> <br>Best wishes,<br> <font color='CC0000'> departmentname South Africa</td> </tr> </table><br><br> </td> </table> </td> </table> </html> MESSAGE_PT2; use this for all large multi-line string blocks and life should get much easier. Just a note, when closing the heredoc you can not have any leading white space at the start of the line, it must be the first thing on that line. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390501 Share on other sites More sharing options...
SalientAnimal Posted November 6, 2012 Author Share Posted November 6, 2012 Ok cool, I now have the picture attaching etc. but, sadly only the first picture seems to attach. The second one doesn't. Also outlook is disabling the pictures from automatically displaying... Is there a way to force the pictures to display? Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390518 Share on other sites More sharing options...
Muddy_Funster Posted November 6, 2012 Share Posted November 6, 2012 not from the senders side. It would require the security settings on the mail client to be tweeked, setting the senders domain to trusted in the junk filter could be enough, but you may also need to change other options as well. it's a common factor, which is why most people have a "having trouble viewing this message? click here" bit in the mail somewhere that links to a web page version. what's the difference between the image files? are they in the same folder on the server? are the file extensions the correct case (href is case sensitive remember) Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390530 Share on other sites More sharing options...
SalientAnimal Posted November 6, 2012 Author Share Posted November 6, 2012 (edited) The images are both in the same location on the server. I have tried various images from this folder. the only difference is that the one image is a full background image for the entire page and the other image is an image embeded in a table. Here are the codes for the images: <body background='http://servername/img/mail_bg_main.jpg' alt='Background Image' width='100%' height='100%'><font face='Arial' size='2' color='white'> <table border='1' background='http://servername/img/mailbg.jpg' alt='Message Background Image' width='85%' align='center'><font face='Arial' size='2' color='white'> The image in the body tag works. The image in the table tag doesn't work. Edited November 6, 2012 by SalientAnimal Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390539 Share on other sites More sharing options...
Pikachu2000 Posted November 6, 2012 Share Posted November 6, 2012 There's a missing closing curly brace. That's all I see wrong. Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390540 Share on other sites More sharing options...
Muddy_Funster Posted November 6, 2012 Share Posted November 6, 2012 (edited) you could try <table border='1' style='background-image:url("http://servername/img/mail_bg.jpg");width:85%;font-family:Arial;font-size:small;color:white;'> I've never tried to apply a background image to a table before, but I have had tables be strangly fussy about how they take style info. You better check the url I used, it's got an underscore in it, as that's what was in your original post, but I see in your last one there it's not got one... Edited November 6, 2012 by Muddy_Funster Quote Link to comment https://forums.phpfreaks.com/topic/270077-html-rich-e-mail-from-php-form/#findComment-1390542 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.