SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP email in HTML format

    I'm trying to send an email in html format. my code is as follows. I've tried using a content type before the body of the email, but it isn't configured correctly since it isn't working.

    please help

    Code:
    <?php
    $connection = mysql_connect("localhost", "", "") or die ("Couldn't connect to the server.");
    $db 		= mysql_select_db("", $connection) or die ("Couldn't select database.");
    $sql 		= "select * from Speedpay_Main where LoanAcctNo = '$acctNumber'";
    $SQLresult	= mysql_query($sql, $connection) or die("1");
    					while ($row	= mysql_fetch_array($SQLresult)){
    							$firstName		=	$row["firstName"];
    							$lastName		=	$row["lastName"];
    							$email			=	$row["email"];
    					}
    $sql2		= "select * from Speedpay_loanInfo where transID = '$maxTransID'";
    $SQLresult2 = mysql_query($sql2, $connection) or die("2");
    					while ($row = mysql_fetch_array($SQLresult2)){
    							$monthlyMrtg		= $row["monthlyMrtg"];
    							$code				= $row["code"];
    							$lstPmt				= $row["lstPmt"];
    							$minPmt				= $row["minPmt"];
    							$totalPmt			= $row["totalPmt"];
    							$lstPmtAmt			= $row["lstPmtAmt"];
    							$transID			= $row["transID"];
    							$transaction		= $row["transaction"];
    							$checkNum			= $row["checkNum"];
    							$checkFeeNum		= $row["checkFeeNum"];
    					}
    
    $mail_to		= $email;
    $mail_from		= "SammyD";
    $mail_subject	= "Your Speedpay confirmation email";
    $mail_body		= "Content-type: text/html; charset=us-ascii";
    $mail_body		.= "<html><head><title>Speedpay Confirmation email for ".$firstName." ".$lastName."</title></head>\n";
    $mail_body		.= "<body><table><tr><td>Name: </td><td>".$firstName." ".$lastName."</td></tr>";
    $mail_body		.= "<tr><td>Last Payment: </td><td>".$lstPmt ."</td></tr>\n";
    $mail_body		.= "<tr><td>Confirmation number: </td><td>".$transID ."</td></tr>\n";
    $mail_body		.= "<tr><td>Check number: </td><td>".$checkNum ."</td></tr>\n";
    $mail_body		.= "<tr><td>Check number for Fee: </td><td>".$checkFeeNum ."</td></tr>\n";
    $mail_body		.= "</table></body></html>\n";
    
    if(mail($mail_to, $mail_subject, $mail_body))
    	echo "Thank you for using Speedpay.  A confirmation email has been sent to your default email address of: ".$email;
    	else echo "Failed!";
    
    ?>

    THANKS,
    dlg

  2. #2
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The MIME type (Content-type: text/html; charset=us-ascii) should always go inside the header (ie. the fourth parameter of the mail() function), and not the body.
    Last edited by cupid; Nov 14, 2001 at 16:10.

  3. #3
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You also don't need every instance of $mail_body. The repeated " will be destroying it.
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  4. #4
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by weirdbeardmt
    You also don't need every instance of $mail_body. The repeated " will be destroying it.
    weirdbeard, I don't think that would be a problem since he's using the .= assignment operator, which instead of overwriting the old variable, it concatenates it.

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea, $mail_body is fine.
    i use that when i send out mails.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


Bookmarks

Posting Permissions

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