Page 1 of 1

::::Help! send html mail to client and to myself::::

Posted: Thu Jul 12, 2007 12:20 am
by prasitc2005
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi 

Please help how to send html mail to client and to myself with different headers and message using if (mail())}{
(if a mail is sent to client and me ,different headers and messages will go to client and to me as well. If a mail is sent to me, it will show a product code and not to a client mail)

Is there something wrong in:
if (mail ($email,'Order',$message,$headers)){}
statement?


The code I have problem with is this:

Code: Select all

# -=-=-=- MIME BOUNDARY
$mime_boundary .= "----Sales Department----";

# -=-=-=- MAIL HEADERS

$eol="\r\n";
$Bcc = 'test@test.com';

if (mail ($email,'Order',$message,$headers)){
# -=-=-=- MAIL HEADERS to Client
$headers .= "Content-Type: text/html; charset=ISO-8859-1 ".$eol;
$headers .= "MIME-Version: 1.0 ".$eol;
$headers .= 'From: Sales Department<'.$Bcc.'>'.$eol;
$headers .= 'Reply-To: Sales Department<'.$Bcc.'>'.$eol;
$headers .= 'Return-Path: Sales Department<'.$Bcc.'>'.$eol; 
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v" .phpversion().$eol; 
# -=-=-=- HTML EMAIL PART
$message .= "<html>\n";
$message .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"default.css\" media=\"screen\">";
$message .= "<link rel=\"stylesheet\"  type=\"text/css\" media=\"print\" href=\"print.css\">";
$message .= "$mime_boundary<br>\n\n";
$message .= "ORDER NUMBER: $orderid<br>\n\n";
$message .= "ORDER DATE: $orderdate<br>\n\n";
$message .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:14px; color:#666666;\"><br>\n"; 
$message .= "Dear $ttle\n $fname\n $lname:<br>\n";
$message .= "This email is to confirm that \"We\" have received your order.<br>\n";
$message .= "<font face=\"MS Sans Serif\" size=2 color=#F2007A>Your delivery details:</font><br>\n\n";
$message .= "Address:$addr1, $addr2, <br>\n\n";
$message .= "City: $city<br>\n\n";
$message .= "County: $county<br>\n\n";
$message .= "Country: $country<br>\n\n";
$message .= "Postal Code: $pcode <br>\n\n";
$message .= "Telephone: $phone<br>\n\n";
$message .= "Fax: fax<br>\n\n";
$message .= "Email: $email<br>\n\n";
$message .= "<font face=\"MS Sans Serif\" size=2 color=#F2007A>Your payment details:</font><br>\n\n";
$message .= "Name on Card: $card_name<br>\n\n";
$message .= "Card Type: $cardType<br>\n\n";
$message .= "Card Number: $cardNumber<br>\n\n";
$message .= "Card Code: $card_code<br>\n\n";
$message .= "Card Expiry: $cardMonth, $cardYear<br>\n\n";
$message .= "<br>\n";
$message .= "<font face=\"MS Sans Serif\" size=2 color=#F2007A>Your ordered items:</font><br>\n\n";
$message .= "<table  border=1 cellpadding=0 cellspacing=0 width = 50% bordercolor=#eeeeee align=left>";
$message .= "<tr bordercolor=#CCCCFF bgcolor=#eeeeee align=center>";
$message .= "<th width=100%><h4><div align=center>Product Description</div></h4></th>";
$message .= "<th width=100%><h4><div align=center>Unit Price</div></h4></th>";
$message .= "<th width=100%><h4><div align=center>Quantity</div></h4></th>";
$message .= "<th width=100%><h4><div align=center>Total Unit Price</div></h4></th>";
$message .= "</tr>";
foreach ($cart as $code => $qty) {
$product = get_product_details($code);
$message .= "<tr>";
$message .= "<td>";
$message .= "<a href = \"www.test.com/price_details.php?code=".$code."\"><font face=\"MS Sans
Serif\" size=2>".$product["name"];
if($product["colour"]!="") { 
$message .= " (".$product["colour"].")"; }
if($product["watt"]!="") { 
$message .= " (".$product["watt"].")"; }
if($product["lamptype"]!="") { 
$message .= " (".$product["lamptype"].")"; }
if($product["mounting"]!="") { 
$message .= " (".$product["mounting"].")"; }

$message .= "</font></a></td>";  
$message .= "<td align = right><font face=\"MS Sans Serif\" size=2>&pound;".number_format($product["price"], 2) ."</font></td>";
$message .= "<td align = right><font face=\"MS Sans serif\" size=2>".$qty."</font>";  
$message .= "</td><td align = right><font face=\"MS Sans Serif\" size=2>&pound;" .number_format($product["price"]*$qty,2). "</font></td></tr>\n"; 
} 
$message .= "<tr bgcolor=#FFFFFF>";  
$message .= "<th align = left colspan=3><font face=\"MS Sans Serif\" size=2 color=#666666>Total(Excl VAT & Shipping fees)</th>";  
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#666666>&pound;".number_format($total_price, 2)."</th></tr>"; 
$message .= "<tr bgcolor=#FFFFFF>";  
$message .= "<th align = left colspan=3><font face=\"MS Sans Serif\" size=2 color=#000>Shipping fees(UK delivery only)</th>"; 
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#000>&pound;".number_format($ukship, 2)."</th></tr>";	  
$message .= "<th align = left colspan=4><font face=\"MS Sans Serif\" size=1 color=#000>* When the payment is through, the products are in the stock and you place order before 14:00, the products will be delivered the next day between 09:00 - 17:00</th></tr>";
$message .= "<tr bgcolor=#FFFFFF>";
$message .= "<th align = left colspan=3><font face=\"MS Sans Serif\" size=2 color=#000>VAT 17.5%</th>";  
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#000>&pound;".number_format($tax, 2)."</th></tr>";  	 
$message .= "<tr bgcolor=#FFFFFF>";  
$message .= "<th align = left colspan=2><font face=\"MS Sans Serif\" size=2 color=#F2007A>Payment Due</th>"; 
$message .= "<th align = center><font face=\"MS Sans Serif\" size=2>$items</th>";  
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#F2007A>&pound;".number_format($grand_total, 2)."</th></tr>";
$message .= "<th align = left><font face=\"MS Sans Serif\" size=2 color=#F2007A>Thank you for shopping with us.</th></tr>";
$message .= "</tr>\n";
$message .= "</td>\n";
$message .= "</body>\n";
$message .= "</html>\n";
}


if (mail($Bcc,'Client Order',$message,$headers)){

# -=-=-=- MAIL HEADERS to Me
$headers .= "Content-Type: text/html; charset=ISO-8859-1 ".$eol;
$headers .= "MIME-Version: 1.0 ".$eol;
$headers .= 'From: Client Order<'.$email.'>'.$eol;
$headers .= 'Reply-To: Client Order<'.$email.'>'.$eol;
$headers .= 'Return-Path: Client Order<'.$email.'>'.$eol; 
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v" .phpversion().$eol; 

# MAIL to Me with product code
# -=-=-=- HTML EMAIL PART
$message .= "<html>\n";
$message .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"default.css\" media=\"screen\">";
$message .= "<link rel=\"stylesheet\"  type=\"text/css\" media=\"print\" href=\"print.css\">";
$message .= "$mime_boundary<br>\n\n";
$message .= "ORDER NUMBER: $orderid<br>\n\n";
$message .= "ORDER DATE: $orderdate<br>\n\n";
$message .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:14px; color:#666666;\"><br>\n"; 
$message .= "Dear $ttle\n $fname\n $lname:<br>\n";
$message .= "This email is to confirm that \"We\" have received your order.<br>\n";
$message .= "<font face=\"MS Sans Serif\" size=2 color=#F2007A>Your delivery details:</font><br>\n\n";
$message .= "Address:$addr1, $addr2, <br>\n\n";
$message .= "City: $city<br>\n\n";
$message .= "County: $county<br>\n\n";
$message .= "Country: $country<br>\n\n";
$message .= "Postal Code: $pcode <br>\n\n";
$message .= "Telephone: $phone<br>\n\n";
$message .= "Fax: $fax<br>\n\n";
$message .= "Email: $email<br>\n\n";
$message .= "<font face=\"MS Sans Serif\" size=2 color=#F2007A>Your payment details:</font><br>\n\n";
$message .= "Name on Card: $card_name<br>\n\n";
$message .= "Card Type: $cardType<br>\n\n";
$message .= "Card Number: $cardNumber<br>\n\n";
$message .= "Card Code: $card_code<br>\n\n";
$message .= "Card Expiry: $cardMonth, $cardYear<br>\n\n";
$message .= "<br>\n";
$message .= "<font face=\"MS Sans Serif\" size=2 color=#F2007A>Your ordered items:</font><br>\n\n";
$message .= "<table  border=1 cellpadding=0 cellspacing=0 width = 50% bordercolor=#eeeeee align=left>";
$message .= "<tr bordercolor=#CCCCFF bgcolor=#eeeeee align=center>";
$message .= "<th width=50%><h4><div align=center>Product Description</div></h4></th>";
$message .= "<th width=20%><h4><div align=center>Product Code</div></h4></th>";
$message .= "<th width=10%><h4><div align=center>Unit Price</div></h4></th>";
$message .= "<th width=10%><h4><div align=center>Quantity</div></h4></th>";
$message .= "<th width=10%><h4><div align=center>Total Unit Price</div></h4></th>";
$message .= "</tr>";
foreach ($cart as $code => $qty) {
$product = get_product_details($code);
$message .= "<tr>";
$message .= "<td>";
$message .= "<a href = \"www.test.com/price_details.php?code=".$code."\"><font face=\"MS Sans
Serif\" size=2>".$product["name"];
if($product["colour"]!="") { 
$message .= " (".$product["colour"].")"; }
if($product["watt"]!="") { 
$message .= " (".$product["watt"].")"; }
if($product["lamptype"]!="") { 
$message .= " (".$product["lamptype"].")"; }
if($product["mounting"]!="") { 
$message .= " (".$product["mounting"].")"; }

$message .= "</font></a></td>"; 
$message .= "<td align = left><font face=\"MS Sans serif\" size=1>$code</font>";
$message .= "<td align = right><font face=\"MS Sans Serif\" size=2>&pound;".number_format($product["price"], 2) ."</font></td>";
$message .= "<td align = right><font face=\"MS Sans serif\" size=2>".$qty."</font>";  
$message .= "</td><td align = right><font face=\"MS Sans Serif\" size=2>&pound;" .number_format($product["price"]*$qty,2). "</font></td></tr>\n"; 
} 
$message .= "<tr bgcolor=#FFFFFF>";  
$message .= "<th align = left colspan=4><font face=\"MS Sans Serif\" size=2 color=#666666>Total(Excl VAT & Shipping fees)</th>";  
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#666666>&pound;".number_format($total_price, 2)."</th></tr>"; 
$message .= "<tr bgcolor=#FFFFFF>";  
$message .= "<th align = left colspan=4><font face=\"MS Sans Serif\" size=2 color=#000>Shipping fees(UK delivery only)</th>"; 
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#000>&pound;".number_format($ukship, 2)."</th></tr>";	  
$message .= "<th align = left colspan=4><font face=\"MS Sans Serif\" size=1 color=#000>* When the payment is through, the products are in the stock and you place order before 14:00, the products will be delivered the next day between 09:00 - 17:00</th></tr>";
$message .= "<tr bgcolor=#FFFFFF>";
$message .= "<th align = left colspan=4><font face=\"MS Sans Serif\" size=2 color=#000>VAT 17.5%</th>";  
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#000>&pound;".number_format($tax, 2)."</th></tr>";  	 
$message .= "<tr bgcolor=#FFFFFF>";  
$message .= "<th align = left colspan=3><font face=\"MS Sans Serif\" size=2 color=#F2007A>Payment Due</th>"; 
$message .= "<th align = center><font face=\"MS Sans Serif\" size=2>$items</th>";  
$message .= "<th align = right><font face=\"MS Sans Serif\" size=2 color=#F2007A>&pound;".number_format($grand_total, 2)."</th></tr>";
$message .= "<th align = left colspan=4><font face=\"MS Sans Serif\" size=2 color=#F2007A>Thank you for shopping with us.</th></tr>";
$message .= "</tr>\n";
$message .= "</td>\n";
$message .= "</body>\n";
$message .= "</html>\n";
}


# -=-=-=- SEND MAIL
mail ("$email","Order",$message,$headers);
mail("$Bcc","Client Order",$message,$headers);
echo '<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=http://www.test.com/thanks.html">';
Thanks a lot! All help is appreciated.




feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: ::::Help! send html mail to client and to myself::::

Posted: Thu Jul 12, 2007 1:08 am
by Christopher
prasitc2005 wrote: Is there something wrong in:
if (mail ($email,'Order',$message,$headers)){}
statement?
Maybe I am missing something, but the first thing I notice is that you are calling the mail() function in the if() before setting $message and $headers. And then you are calling mail() again at the end twice when it has perhaps failed twice above. I see where $Bcc is set, but what about $email?

I would recommend trying SwiftMailer...

Posted: Fri Jul 13, 2007 7:21 am
by prasitc2005
Hi

Thanks. I have tried what you suggested but nothing was solved. Can you suggest any good tutorial where I can send order form to a client and to myself using different headers and message for a client mail and my mail. $email = client's mail on mysql database, $Bcc = my mail

Thanks a lot

Posted: Fri Jul 13, 2007 7:23 am
by prasitc2005
Can't I do $headers2 and $message2 for the mail to myself. I tried this but php doesn't accept to send.

Posted: Fri Jul 13, 2007 7:37 am
by prasitc2005
I found something so this might clear things up:

OK! Now that we have all our data elements we can send out our confirmation email, and another to our own "Order Processing Department" to let them (our self, perhaps?!!) know that an order has been entered. One thing to remember when sending out these confirmation emails, though it doesn't apply to our present example, is that it is unwise (or worse) to include any credit card information in an email. It's always worth paying attention to the kind of information you do send via email -- sensitive information is just that, sensitive.

So, to the emails:

Code: Select all

//we have our data, and now build up an email message to send
$mailto = "orders@ourdomain.com";
$subject = "Web Order";
 
$body  = "The following confirms the details of your order:\n";
$body .= "\n\n";
$body .= "Name: " . $Name . "\n";
$body .= "Email: " . $Email . "\n";
$body .= "Other Contact Info: " . $OtherInfo . "\n";
$body .= "\n\n";
$body .= "Class A Widgets: (" . $qtyA . " * 1.25) = " . $totalA . "\n";
$body .= "Class B Widgets: (" . $qtyB . " * 2.35) = " . $totalB . "\n";
$body .= "Class C Widgets: (" . $qtyC . " * 3.45) = " . $totalC . "\n";
$body .= "\n";
$body .= "TOTALS: " . $GrandTotal . "\n";
 
mail($mailto, $subject, $body);
mail($Email, $subject, $body);
Note that when building the body of the email, the first line uses the assignment operator = while the remaining use the concatenate assignment operator .= I thought it worth a mention because it's easy to miss the period.
If you wanted to have a different lead line for your order department than for the customer's confirmation email, you could build a second body and send that one to your order desk.
[/quote]

Posted: Fri Jul 13, 2007 9:01 am
by onion2k
Seriously, use Swiftmailer. There's no better solution for sending HTML emails.