inthewayboy Posted February 27, 2009 Share Posted February 27, 2009 Okay, so I normally just bang my head against the screen until I figure it out, but I'm kinda pressed for time this go around so I'm gonna reach out! I'm trying to setup a function that will send an email to a user in both text and html formats. I've got that working in a rather ugly way, but I'm trying to clean it up and one of those tasks is to remove the message body to files that can be edited separately from the php code. So to be crystal clear, I have three files: [*]axs_mail.php [*]message_text.php [*]message_html.php axs_mail.php is what is doing all the work, and the other two are the templates. Let me post my code too, that might help: axs_mail.php: <?php #Script Start #Include Files include("Mail.php"); include("Mail/mime.php"); #axs_mail function axs_mail($email_address,$account_no,$account_name,$contact_name,$btn,$total_balance,$overdue_days,$overdue_amount) { $hdrs=array("From"=>"billing@xxx.com","Subject"=>"Mail Message"); #Create Message $mime=new Mail_mime("\n"); $mime->setTXTBody(include("message_text.php"),true); $mime->setHTMLBody(include("message_html.php"),true); $body=$mime->get(); $hdrs=$mime->headers($hdrs); #Send Message $mail=&Mail::factory("mail"); $mail->send($email_address,$hdrs,$body); } axs_mail("xxx@gmail.com","ACC-1111111","","Lee","(904) 555-1234","392.93","30","129.93"); ?> message_text.php: <?php echo nl2br("Dear ".$contact_name.",\n"); echo nl2br("\n"); echo nl2br("Our records indicate that your account (".$account_no.") is currently ".$overdue_days." days past due. The total balance of your account is ".$total_balance.", and to continue service we will require an immediate payment of ".$overdue_amount.". You may send your payment electronically using our web-based payment system, or you can call us directly at (xxx) xxx-xxxx. We appreciate your business and hope that you continue to enjoy our services.\n"); echo nl2br("\n"); echo nl2br("Sincerely,\n"); echo nl2br("\n"); echo nl2br("xxx Billing Department\n"); ?> message_html.php: <html> <head> <title> Access Communications </title> </head> <body> <p> Dear <?php echo($contact_name);?>, </p> <p> Our records indicate that your account (<?php echo($account_no);?>) is currently <?php echo($overdue_days);?> days past due. The total balance of your account is <?php echo($total_balance);?>, and to continue service we will require an immediate payment of <?php echo($overdue_amount);?>. You may send your payment electronically using our web-based payment system, or you can call us directly at (xxx) xxx-xxxx. We appreciate your business and hope that you continue to enjoy our services. </p> <p> Sincerely, </p> <p> xxx Billing Department </p> </body> </html> As you can see both templates have variables placed in them that I would like to be parsed/replaced before being sent. As it stands if I run that code (Using valid email addresses of course) I get both templates displayed in the browser with the correct replacements, but the emails are blank. Now I'm really new at all this, so I understand include may not be the best way to handle this...I basically want the files to be opened, the variables replaced, and then emailed...seems simple enough? I know I'm just right there if I can get the right info to show up in the browser (Even though I'm not echo/printing it...maybe a byproduct of include?) but I'm too frustrated to figure it out. This will eventually be a component of a project that imports a csv file into a mysql database and then sends emails to account that are past due...I've got all the rest working but this! Grrrr! Thanx in advance!!! Quote Link to comment Share on other sites More sharing options...
inthewayboy Posted February 27, 2009 Author Share Posted February 27, 2009 between switching to phpmailer and running the two files though an implode+eval it's working great now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.