Jump to content

Sending an HTML E-Mail


stublackett

Recommended Posts

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

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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  :confused:

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.