Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts

    mail() Sending HTML Message

    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.)

    Code:
    				$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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Well where is $message defined? I don't see it in the code you posted.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts
    $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.

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    post your whole code as the problem could lie there.

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Code to send email - The rest of the code in this document is just forms and field checking as well as mysql queries.

    PHP Code:
                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 Code:
    <?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>'
    ;

    ?>
    Last edited by NeoPuma; 03-05-2008 at 01:11 AM.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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).

  • #7
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Thanks for the reply. Have tried it so it now reads:
    PHP Code:
    $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

  • #8
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    so some of the HTML is working?

  • #9
    Regular Coder
    Join Date
    Oct 2004
    Posts
    104
    Thanks
    7
    Thanked 2 Times in 2 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •