...

View Full Version : mail() Sending HTML Message



NeoPuma
03-05-2008, 12:44 AM
Hey,
I'm trying to send an email for newly registered members. I've got the following code (minus the message) to send to email. The headers were copied from php.net. (Name and email has been removed for the purpose of this post.)


$to = $_POST['user_email'];
$subject = 'Thank-you for registering';

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: '.$_POST['user_name1'].' '.$_POST['user_name2'].' <'.$_POST['user_email'].'>' . "\r\n";
$headers .= 'From: *********** <*********.co.uk>' . "\r\n";

// Send
mail($to, $subject, $message, $headers);

The email arrives, but without actual content? I'm not entirely sure why, but I would like to know so it can be fixed. So any help at all, would be grateful.

Thanks

_Aerospace_Eng_
03-05-2008, 12:46 AM
Well where is $message defined? I don't see it in the code you posted.

NeoPuma
03-05-2008, 12:52 AM
$message wern't posted due to the size of it. It contains a fair bit of HTML. I did say that in my first post:
"I've got the following code (minus the message) to send to email"

It's defined in an external file (for editing ease) and included.

rafiki
03-05-2008, 12:55 AM
post your whole code as the problem could lie there.

NeoPuma
03-05-2008, 01:08 AM
Code to send email - The rest of the code in this document is just forms and field checking as well as mysql queries.



if($result === FALSE) {
error('MySQL Error', 'There was a database error. Please try again later');
} else {
include('scripts/register_email.php');

$to = $_POST['user_email'];
$subject = 'Thank-you for registering';

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: '.$_POST['user_name1'].' '.$_POST['user_name2'].' <'.$_POST['user_email'].'>' . "\r\n";
$headers .= 'From: Baby Bloom Boutique <registrations@babybloom.neopian.co.uk>' . "\r\n";

// Send
mail($to, $subject, $message, $headers);

echo 'Thank-you for signing up. We have sent you an email confirming your details. You can however, log in straight away and start shopping!<br/><br/>
Enjoy!';

The Email - this is basically the html from the site design with content added.

<?php

$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="http://www.babybloom.neopian.co.uk/style.css" rel="stylesheet" />
<title>Baby Bloom Boutique</title>
</head>

<body>

<div id="top">
&nbsp;
</div>
<div id="mainnav">
<a href="http://www.babybloom.neopian.co.uk/?p=home">Home</a>
<a href="http://www.babybloom.neopian.co.uk/?p=about">About Us</a>
<a href="http://www.babybloom.neopian.co.uk/?p=shops">Shops</a>
<a href="http://www.babybloom.neopian.co.uk/?p=search">Search</a>
<a href="http://www.babybloom.neopian.co.uk/?p=contact">Contact Us</a>
</div>

<div id="main_frame">
<div id="left">
<strong>Thank-you for registering with Baby Bloom Boutique!</strong>
</div>
<div id="right">
Dear '.$_POST['user_title'].' '.$_POST['user_name2'].'<br/><br/>
Thank-you for registering at Baby Bloom Boutique. You can now log in and start your shopping right away!<br/>
Please take your time to check the details you enetered (listed below), and correct them if required by logging in on our web site.<br/><br/>
<strong>Name</strong>: '.$_POST['user_title'].' '.$_POST['user_name1'].' '.$_POST['user_name2'].'<br/>
<strong>Address Line 1</strong>: '.$_POST['user_address1'].'<br/>
<strong>Address Line 2</strong>: '.$_POST['user_address2'].'<br/>
<strong>Address Line 3</strong>: '.$_POST['user_address3'].'<br/>
<strong>Town</strong>: '.$_POST['user_town'].'<br/>
<strong>County</strong>: '.$_POST['user_county'].'<br/>
<strong>Post Code</strong>: '.$_POST['user_postcode'].'<br/>
<strong>Telephone No. 1</strong>: '.$_POST['user_tel1'].'<br/>
<strong>Telephone No. 2</strong>: '.$_POST['user_tel2'].'<br/><br/>
If you have any questions, please visit our web site for details to contact us.<br/>
Replys to this address <strong>will not</strong> be read.<br/><br/>

Thank-you
Baby Bloom Boutique
</div>
</div>

<div id="copyright">
&copy; Baby Bloom Boutique 2008
</div>

<div id="validation">
<a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Transitional" style="height:31px;width:88px;border:0;" />
</a>
<a href="http://jigsaw.w3.org/css-validator/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-css.png"
alt="Valid CSS!" style="height:31px;width:88px;border:0;" />
</a>
</div>

</body>
</html>';

?>

Inigoesdr
03-05-2008, 01:24 AM
Not sure if it's the cause, but you're using two different charsets(iso-8859-1 in the mail headers, and utf-8 in the html source).

NeoPuma
03-05-2008, 01:30 AM
Thanks for the reply. Have tried it so it now reads:

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
However, this had no effect on it. It's unchanged.

Just for you to see what's happening, this is a typical email:


Home About Us Shops Search Contact Us
Thank-you for registering with Baby Bloom Boutique!
Dear Mr Jones

Thank-you for registering at Baby Bloom Boutique. You can now log in and start your shopping right away!
Please take your time to check the details you enetered (listed below), and correct them if required by logging in on our web site.

Name: Mr Bob Jones
Address Line 1: ***********
Address Line 2:
Address Line 3:
Town: ********
County: **********
Post Code: **** ***
Telephone No. 1: ***** ******
Telephone No. 2:

If you have any questions, please visit our web site for details to contact us.
Replys to this address will not be read.

Thank-you Baby Bloom Boutique
&#169; Baby Bloom Boutique 2008
http://www.w3.org/Icons/valid-xhtml10 http://www.w3.org/Icons/valid-css.png

rafiki
03-05-2008, 01:44 AM
so some of the HTML is working?

NeoPuma
03-05-2008, 01:49 AM
Yea, but only the things like the bold, the links, and the two images at the bottom, but that is literally it (as you can see).

Just thinking of it, it includes a stylesheet - is it likely to be that rather than the email headers? I mean, I don't usually work with the mail() function so I'm not entirely sure about what's happening and how to fix etc.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum