stublackett Posted January 21, 2011 Share Posted January 21, 2011 Hi Guys, I've got a contact form set up, where the user can submit their design they have created on the site. The file uploads to a directory titled "Uploads" and the idea would then be set up a link within an HTML style E-Mail, I've had a look at MIME-TYPE on the php.net manual. I've got the form to work to an extent, however the PHP variables are not being echo'ed out and the E-Mail looks like this : <html> <body> <b>New Design by $name </b> <p>Contact Details...</p> Telephone : $telephone<br /> E-Mail : $email<br /> Design : <a href=http://wwww.mysite.co.uk/Mail%20Test/uploads/$upfile>$upfile</a> </body> </html> New EasyFluid Design Added My Code is as follows : <?php $to = ""; // User E-Mail $subject = "New Design Added"; // The Subject //$target_path = "uploads/"; // $target_path = $target_path . basename( $_FILES['design']['name']); //if(move_uploaded_file($_FILES['design']['tmp_name'], $target_path)) { //} extract($_POST); $from = "From: {$_POST['name']} <{$_POST['email']}>"; // From (the field named "name" and the email field named "email" //Handle the Image $upfile = 'uploads/' .$_FILES['design']['name'] ; if (is_uploaded_file($_FILES['design']['tmp_name'])) { if (!move_uploaded_file($_FILES['design']['tmp_name'], $upfile)) { echo 'Problem : Could not move file to destination directory'; exit; } } $message = ' <html> <body> <b>New Design by $name </b> <p>Contact Details...</p> Telephone : $telephone<br /> E-Mail : $email<br /> Design : <a href=http://wwww.mysite.co.uk/Mail%20Test/uploads/$upfile>$upfile</a> </body> </html> '; // 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"; mail($to, $from, $subject, $message, $headers); // HTML Style E-Mail ?> Any help on how I can correct this would be much appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
PHPFAN10 Posted January 21, 2011 Share Posted January 21, 2011 however the PHP variables are not being echo'ed out and the E-Mail looks like this : Use double quotes for $message $message = "";. If you use single quotes PHP will output the $variable not the actual text you want to show. Double quotes will sort that out. Also i don't think you need the <html></html> and <body></body> tags. I have never used them in my email templates and never got any problems. Try those above and see if it sorts your problem out. Quote Link to comment Share on other sites More sharing options...
PHPFAN10 Posted January 21, 2011 Share Posted January 21, 2011 Oops i forgot something you need to supply From as an additional header so replace: // 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"; with: // 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" . "\r\n"; and replace: mail($to, $from, $subject, $message, $headers); // HTML Style E-Mail with mail($to, $subject, $message, $headers); // HTML Style E-Mail Quote Link to comment Share on other sites More sharing options...
stublackett Posted January 21, 2011 Author Share Posted January 21, 2011 Thanks for that PHPFAN10. Seems to work quite well in any web-based mail : Gmail, Hotmail seem fine! However the output I'm getting in Outlook 2007 is : Content-type: text/html; charset=iso-8859-1 From: Stuart <email@email.com> X-CTCH-PVer: 0000001 X-CTCH-Spam: Unknown X-CTCH-VOD: Unknown X-CTCH-Flags: 0 X-CTCH-RefID: str=0001.0A090203.4D39945E.0208,ss=1,fgs=0 <b>New Design by Stuart </b> <p>Contact Details...</p> Telephone : 01<br /> E-Mail : user@user.com<br /> Design : <a href=http://wwww.website.com/Mail%20Test/uploads/canon_logo.jpg>Design Here</a> I'm assuming Outlook is looking for a different MIME-TYPE? Quote Link to comment Share on other sites More sharing options...
PHPFAN10 Posted January 21, 2011 Share Posted January 21, 2011 mmm, i'm not sure then i'm afraid. I do like what you have above with the changes i made and in my Outlook 2007 my emails show exactly as they should. Maybe there is a setting you have enabled to disable html in emails or something and to display headings? I can't see anything wrong now with that code I can remember having a similar problem once and cannot for the life of me think what i done to fix it. It's bugging me trying to think what i did but it has been a long time now so can't think. Quote Link to comment Share on other sites More sharing options...
stublackett Posted January 21, 2011 Author Share Posted January 21, 2011 Interesting that it works on your Outlook 2007. It also works a treat in Webmail. Thanks for your help though! I'm going to hunt through Outlook Settings now, see if I can work out if theres anything in there. Quote Link to comment Share on other sites More sharing options...
PHPFAN10 Posted January 21, 2011 Share Posted January 21, 2011 Yep just tested code and works fine on my Outlook 2007. Make sure you done the changes i said also. Quote Link to comment 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.