html email not working

Discussion in 'PHP' started by parkerproject, Jan 10, 2009.

  1. #1
    my html email is not outputting html format instead it is showing the tags



    
    // format body text
    
    
    
    $line = "Know the rules! Know the stakes! Know when to quit!";
    
    
    
    
    
    
    
    /**
    
     * Setup the e-mail information
    
     */
    
    
    
    $subject = "New Trade Alert";
    
    //$body
    
    
    
    $body = "<html>
    
    <head>
    
    <title>Title</title>
    
    </head>
    
    <body>
    
    <table>
    
    <tr>
    
    <td class=\"line\">$line
    
    </td>
    
    </tr>
    
    </table>
    
    </body>
    
    </html>";
    
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    $headers = "From: <tradealerts@website.com>\r\n";
    
    $headers .= "Reply-To: tradealerts@website.com";
    
    
    
    /**
    
     * Grab the e-mails from the database, and e-mail them to the user.
    
     */
    
    
    
    $query = mysql_query("SELECT * FROM member WHERE trader='$trader' AND subscribe='yes'");
    
    while ($row = mysql_fetch_array($query)) {
    
        if (mail($row["email"], $subject, $body, $headers)) {
    
            // email was a success, sent
    
        } else {
    
            // sending of e-mail was a failure
    
        }
    
    } 
    
    PHP:
     
    parkerproject, Jan 10, 2009 IP
  2. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Look at your header variable:
    
    $headers .=
    $headers =
    $headers .=
    
    PHP:
    See, the 2nd time, you reset the variable so you don't parse the html header.

    This should work:
    
    // format body text
    
    
    
    $line = "Know the rules! Know the stakes! Know when to quit!";
    
    
    
    
    
    
    
    /**
    
     * Setup the e-mail information
    
     */
    
    
    
    $subject = "New Trade Alert";
    
    //$body
    
    
    
    $body = "<html>
    
    <head>
    
    <title>Title</title>
    
    </head>
    
    <body>
    
    <table>
    
    <tr>
    
    <td class=\"line\">$line
    
    </td>
    
    </tr>
    
    </table>
    
    </body>
    
    </html>";
    
    $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    $headers .= "From: <tradealerts@website.com>\r\n";
    
    $headers .= "Reply-To: tradealerts@website.com";
    
    
    
    /**
    
     * Grab the e-mails from the database, and e-mail them to the user.
    
     */
    
    
    
    $query = mysql_query("SELECT * FROM member WHERE trader='$trader' AND subscribe='yes'");
    
    while ($row = mysql_fetch_array($query)) {
    
        if (mail($row["email"], $subject, $body, $headers)) {
    
            // email was a success, sent
    
        } else {
    
            // sending of e-mail was a failure
    
        }
    
    } 
    
    PHP:
     
    elias_sorensen, Jan 11, 2009 IP
  3. FitchIndy

    FitchIndy Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I agree with elias, your second $headers line is overwriting your first $headers line, use .= to append
     
    FitchIndy, Jan 11, 2009 IP