Categories > Your tips & tricks >

How can I send a email with TBS?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Aureo
Date: 2005-09-28
Time: 20:17

How can I send a email with TBS?

I need send email with TBS. How can I do it ? Give me a example please.
By: Skrol29
Date: 2005-09-28
Time: 22:14

Re: How can I send a email with TBS?

Hi Aureo,

You can easily prepare the body contents of you email with TBS.
Then you can send it using your method. For exemple using Php function mail(). But sending is not the part of TBS.

Here is a basic example of how you can send an email for each row of a table:
// Open the MySQL query
$qid = mysql_query('SELECT * FROM t_invoice');

// Load the template, and save the source
// Remark: value false is used because the template is simple text, and it avoid Html conversion.
$TBS->LoadTemplate('email_body.txt,false);
$save_body = $TBS->Source;

// Prepare TBS to not exit at the end of the Show method
$TBS->Render =  TBS_NOTHING;

// Loop for all invoces to send by email
while ($inv_info = mysql_fetch_assoc($qid)) {
  // Retrieve initial source
  $TBS->Source = $save_body;
  // Merge invoice data
  $TBS->MergeBlock('inv',$inv_info);
  // Merge items of the invoices
  $TBS->MergeBlock('items',$mysql_id,'SELECT * FROM t_items WHERE inv_code='.$inv_info['id']);
  // Merge automatic fields
  $TBS->Show();
  // Send the email
  $to = $inv_info['email'];
  $subject = 'your invoice';
  mail($to,$subject,$TBS->Source);
}

If you'd like to send an Html email with embedded pictures, then you have to use the conveniant mime syntax in the body for that. But it has to be put in your template, and you'll also probably need more info about the mail() function.

By: Don Bledsoe
Date: 2007-06-10
Time: 07:11

Re: How can I send a email with TBS?

I am trying to update this to work with TBSsql, but I get the following error and I'm note sure what I'm doing wrong:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

I assume I need to use the TBSsql class, but is $Db->GetRows() the way to do it? Here's what I have so far:
// Open the MySQL query
$qid = $Db->GetRows('SELECT * FROM domains WHERE (expiresdays < 31)');

//$Db->MergeBlock('blk','tbssql','SELECT * FROM domains WHERE (expiresdays < 31)');

// Load the template, and save the source
$TBS->LoadTemplate('tpl/emailnotice.tpl.html');
$emailBody = $TBS->Source;

// Prepare TBS to not exit at the end of the Show method
$TBS->Render =  TBS_NOTHING;

// Loop for all domains to send email notice
while ($domains = mysql_fetch_assoc($qid)) {
   
    // Retrieve initial source
    $TBS->Source = $emailBody;
   
    // Merge invoice data
    $TBS->MergeBlock('blk',$domains);
   
    // Merge automatic fields
    $TBS->Show();
   
    // Send the email
    $To        = $qid['email'] . ", dbledsoe@forefrontinternet.com";
    $From    = "CustomerCare@forefrontinternet.com";
    $Subj    = 'Your Domain Registration is Expiring Soon';
    mail($To,$Subj,$TBS->Source,$From);
}

$Db->Close();

By: Don Bledsoe
Date: 2007-06-10
Time: 13:40

Re: How can I send a email with TBS?

Minor progress when I changed this:
// Loop for all domains to send email notice
while ($domains = mysql_fetch_assoc($qid)) {
to this:
// Loop for all domains to send email notice
while ($domains = @mysql_fetch_assoc($qid)) {

Now, there's no errors, but it doesn't work either.
By: Skrol29
Date: 2007-06-15
Time: 23:50

Re: How can I send a email with TBS?

Hi,

When you do
  $qid = $Db->GetRows(...)
Then $qid contains data, not a ressource id.
Thus, the loop should be :
foreach ($qid as $domains) {

// Retrieve initial source
$TBS->Source = $emailBody;

// Merge invoice data
$TBS->MergeBlock('blk',$domains);

// Merge automatic fields
$TBS->Show();

// Send the email
$To  = $qid['email'] . ", dbledsoe@forefrontinternet.com";
$From = "CustomerCare@forefrontinternet.com";
$Subj = 'Your Domain Registration is Expiring Soon';
mail($To,$Subj,$TBS->Source,$From);
}