tsbadawy Posted May 9, 2007 Share Posted May 9, 2007 I have a working script but it wont send to file as an attachement it just generates the email in the browser like a webpage and sends an empty email. ??? here is my code. It worked untill I needed to use smtp authentication. Eversince I changed the script to use authentication it hasn't worked :-\ <!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=iso-8859-1" /> <title>Generating Emails from Database</title> <style type="text/css"> <!-- .style2 {font-size: 12px} .style3 { font-size: 10px; font-weight: bold; } .style4 { font-size: 20px; font-weight: bold; color: #990000; } .style5 {color: #0000FF} .style6 {color: #FF0000} .style8 {color: #0000FF; font-size: 10px; } .style9 {font-size: 10px} --> </style> </head> <body> <?php require("class.phpmailer.php"); function mail_it($toEmail,$filename) { //echo "$company,$filename,$toEmail"; $mail = ""; $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->Host = "mail.xxxxxxxxx.com"; // specify main and backup server $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "[email protected]"; // SMTP username $mail->Password = "password"; // SMTP password $mail->From = "[email protected]"; $mail->FromName = "E-Invoices"; $mail->AddReplyTo("[email protected]", "TSR-Accounting"); // To email a specific address change $emailadd to that address at the bottom of document $mail->AddAddress ($toEmail); $mail->WordWrap = 100; // set word wrap to 50 characters $mail->AddAttachment("A/". $filename); // add attachments $mail->IsHTML(true); // set email format to HTML $mail->Subject = "xxxxxxxxxx - Monthly Invoice for "; $mail->Body = "Please find your Summary and Detailed Invoice Attached";//$info; if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; $mail->ClearAddresses(); $mail->ClearAttachments(); exit; } echo "Invoice, $filename.html, for $company has been sent to $toEmail.<hr style='margin:0px;padding:0px;border-bottom:1px dashed #777;border-top:0px;border-left:0px;border-right:0px;line-height:0px;height:1px;display:block;' />\n"; $mail->ClearAddresses(); $mail->ClearAttachments(); } $db_connection = new COM("ADODB.Connection"); $db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("einvoicing.mdb") ." ;DefaultDir=". realpath("../"); $db_connection->open($db_connstr); $timestr = date("Y-m-d",strtotime(date('Y-m-j'))); $rs = $db_connection->execute("SELECT * FROM cust"); $ticketnumber= $rs->Fields(0); $method = $rs->Fields(1); $custnum = $rs->Fields(2); $dept = $rs->Fields(3); $bsuite = $rs->Fields(4); $bstreet = $rs->Fields(5); $bcity = $rs->Fields(6); $bstate = $rs->Fields(7); $bzip = $rs->Fields(; $emailadd = $rs->Fields(9); $contact = $rs->Fields(11); $ssuite = $rs->Fields(12); $sstreet = $rs->Fields(13); $scity = $rs->Fields(14); $sstate = $rs->Fields(15); $szip = $rs->Fields(16); while (!$rs->EOF) { $headers1 = "From: [email protected]\r\n"; $headers1 .= 'MIME-Version: 1.0' . "\r\n"; $headers1 .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; $messageTop = <<<EOF <body> <table width="594" border="0" align="center"> <tr> <td width="588"><p align="center"><img src="http://www.xxxxxxxxx.com/invoicemail/header.gif" alt="xxxxxxxxxxx, Inc." width="502" height="100" /> <hr /> </td> </tr> </table> </body> </html> EOF; $messagea="<table width='700' height='86' border='0' align='center'> <tr> <td width='38%' height='82'><div align='left'><span class='style2'> <font size='3' style='font-weight:bold'>Customer# </font>$custnum->value <br /> <font size='3' style='font-weight:bold'>Dept# </font>$dept->value<br /> <font size='3' style='font-weight:bold'>Billing Address:</font><br /> $contact->value<br /> $bsuite->value<br /> $bstreet->value<br /> $bcity->value $bstate->value , $bzip->value</span><br /> </div></td> <td width='24%' align='center' valign='middle'><div align='center'><font size='3' style='font-weight:bold'>$method->value</font><br /> <font size='4' style='font-weight:bold' color='#990000'>Electronic<br /> Invoice</font></div></td> <td width='38%'><table width='100%' border='0'> <tr> <td><table width='100%' border='0'> <tr> <td width='57%'><div align='center'><font size='3' style='font-weight:bold'>Date</font><br /> $timestr</div></td> <td width='43%'><div align='center'><font size='3' style='font-weight:bold'>Invoice Number</font> $ticketnumber->value</div></td> </tr> </table></td> </tr> <tr> <td><div align='center' class='style2'><font size='3' style='font-weight:bold'>Shipping Address:</font><br /> $contact->value<br /> $ssuite->value<br /> $sstreet->value<br /> $scity->value $sstate->value , $szip->value</div></td> </tr> </table></td> </tr> </table>"; $rs2 = $db_connection->execute("SELECT * FROM special"); $invoice2 = $rs2->Fields(1); $commtext = $rs2->Fields(3); $findinvoice2= $rs->Fields(0); $messageb= ""; while (!$rs2->EOF) { $x2= $invoice2->value; $y2= $findinvoice2->value; if($x2==$y2) { $messageb= "<table width='700' border='0' align='center'> <tr> <td align='center'> $commtext->value <hr /> </td> </tr> </table>"; } $rs2->MoveNext(); } $rs2->Close(); $messagec=" <table width='700' border='0' align='center'> <tr> <td><table width='100%' border='0'> <tr bgcolor='#CCCCCC'> <td width='10%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>ITEM NBR.</font></span></td> <td width='7%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>CO.</font></span></td> <td width='17%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>DESCRIPTION</font></span></td> <td width='9%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>UNIT</font></span></td> <td width='11%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>ORDER<br /> QTY</font></span></td> <td width='8%' align='center'><p class='style3'><font size='2' style='font-weight:bold'>B/O<br /> QTY</font></p></td> <td width='8%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>SHIP<br /> QTY</font></span></td> <td width='10%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>UNIT<br /> PRICE</font></span></td> <td width='15%' align='center'><span class='style3'><font size='2' style='font-weight:bold'>EXTENDED</font></span></td> </tr> </table> </td> </tr> </table>"; $rs1 = $db_connection->execute("SELECT * FROM item"); $invoice = $rs1->Fields(1); $company = $rs1->Fields(2); $itemnum = $rs1->Fields(3); $itemdesc = $rs1->Fields(4); $unitmeas = $rs1->Fields(5); $oqty = $rs1->Fields(6); $sqty = $rs1->Fields(7); $boqty = $rs1->Fields(; $sprice = $rs1->Fields(9); $taxes = $rs1->Fields(10); $xsell = $rs1->Fields(11); $findinvoice= $rs->Fields(0); $ttaxes=0; $total=0; $idkey = $rs1->Fields(0); $messaged= ""; while (!$rs1->EOF) { $t= number_format(($sprice->value), 2, '.', ','); $u= number_format(($xsell->value), 2, '.', ','); $v= ($taxes->value)+0; $w= ($idkey->value)+0; $x= $invoice->value; $y= $findinvoice->value; $z= ($xsell->value)+0; $customBG = $w % 2; if ($customBG == 0){ $bcolor="lightyellow"; }else{ $bcolor="white"; } if($x==$y) { $ttaxes = $ttaxes + $v; $total = $total + $z; $messaged.= "<table width='700' align='center'><tr bgcolor=$bcolor> <td width='10%' align='center'>$itemnum->value</td> <td width='7%' align='center'>$company->value</td> <td width='17%' align='center'>$itemdesc->value</td> <td width='9%' align='center'>$unitmeas->value</td> <td width='11%' align='center'>$oqty->value</td> <td width='8%' align='center'>$boqty->value</td> <td width='8%' align='center'>$sqty->value</td> <td width='10%' align='center'>$ $t</td> <td width='15%' align='center'>$ $u</td></tr></table>"; } $rs1->MoveNext(); } $rs1->Close(); $ttotal=($total + $ttaxes); $total= number_format($total, 2, '.', ','); $ttotal= number_format($ttotal, 2, '.', ','); $ttaxes= number_format($ttaxes, 2, '.', ','); if ($ttaxes ==0) { $messagee= "<table width='700' align='center' border='0'> <tr> <td width='71%'><p align='right' class='style5'><strong><font color='#0000FF' size='2' style='font-weight:bold'>Pay This Amount ► </font></strong></p></td> <td align= 'right' width='29%' bgcolor='#CCCCCC'><strong><font color='#0000FF' size='2' style='font-weight:bold'>Total: $ $ttotal</font></strong></td> </tr> </table>"; }else{ $messagee= "<table width='700' align='center' border='0'> <tr> <td width='71%'><p align='right' class='style5'><strong><font color='#0000FF' size='2' style='font-weight:bold'>Pay This Amount ► </font></strong></p></td> <td align= 'right' width='29%' bgcolor='#CCCCCC'><strong><font color='#0000FF' size='2' style='font-weight:bold'>SubTotal: $ $total<br /> Tax: $ $ttaxes<br /> Total: $ $ttotal</font></strong></td> </tr> </table>"; } $messagef= "<table width='700' border='0' align='center'> <tr> <td><hr /> <p><font color='#0000FF' style='font-size:12px; font-family:sans-serif;'>Terms: A service charge of 1-1/2% per month will be assessed after thirty days. This is an annual rate of 18%</font><br /> <font color='#FF0000' style='font-size:12px; font-family:sans-serif;'>Merchandise cannot be returned after 30 days. Please have original packaging for returns.<br /> Must report shortages within five days. Thank you</font></p></td> </tr> </table>"; $messageBottom= "<table width='700' border='0' align='center'> <tr> <td><hr /> <p style='font-size:12px; font-family:sans-serif;'>This message has been sent to $emailadd->value if this is incorrect please contact your sales representative to change the information in the system.<br /> If there are discrepancies in the billing information please call xxxxxxxxxxxx and ask for the Accounts Receivable Department.<br /> If there is a problem with the order please call xxxxxxxxxxx and ask for Customer Service.<br /> You have received this electronic invoice because you have requested for invoicing in this format. If you no longer wish to have electronic invoicing please contact your sales representative.</p></td> </tr> </table>"; $messageall = $messageTop . $messagea . $messageb . $messagec . $messaged . $messagee . $messagef . $messageBottom; //echo $messagea . $messageb. $messagec . $messaged . $messagee . $messagef .$messageBottom; //$emailadd="[email protected]"; //$emailadd="[email protected]"; mail_it($emailadd,$messageall,"E-Invoice ",$headers1); //mail("[email protected]","[COPY]E-Invoice From x",$messageall,$headers1); $rs->MoveNext(); } $rs->Close(); $db_connection->Close(); echo "All e-mails were sent well!"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/50706-php-mailer-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.