How To: Email Db Results To Respective User

Hi,

Any code laying around which would help me email the results of a query to the user concerned?

DB result output to the screen ok (name, email and every row ID concerned in the query) but i’d like to spit it out into an email, queue might be good as there’s likely to be alot of emails sent each day… also via SMTP would be better than phpmail…

I’ve looked at and tried to install extentions but they are geard towards email forms which are over complicated for what i need… perhaps i will use one, and hard code the form part with hidden fields…

I dont want to put in some normal phpmail code :-[ I want to Yii it.

Well i would suggest to right your own code for that according to your requirements and don’t go with any of the extension for it.use threading concept also.If there is too much mails will be sent in a day.

True, im new to Yii, i find it awesome but also really frustrating at the same time (because i dont know it too well)

I’ve used the script on here “Creating A Common Mail Queue?” which is taking my results and putting them into a basic template and storing the email in a ‘queue’ in the DB so that looks good so far…

The issue i have now, is that I dont know how to make it send the emails! :lol:


<? 


$temp2 = '';

foreach($query as $row){

 

  if($row['adviser_id'] != $temp2){

	$var1 = $row['adviser_id'];

	$var2 = $row['adviser_email'];

	$var3 = $row['adviser_firstname'];

	$var4 = $row['adviser_lastname'];

	$var5 = $row['outstanding_visits'];

	

	//echo "<h2><!--[".$row['adviser_id']."]:--> <a href=\"mailto:".$row['adviser_email']."?subject=".$row['outstanding_amount']."&nbsp;Outstanding Visits&amp;body=Dear ".$row['adviser_firstname'].",\n\n The following Leads are missing a Visit Data:" .str_replace(",", ", ", $row['outstanding_lead_ids'])."\n\nPlease advise.\">".$row['adviser_firstname']." ".$row['adviser_lastname']."</a> <span style='color:#ff0000'>(".$row['outstanding_amount'].")</span></h2>";

    $temp2 = $row['adviser_id'];

  }

  $var6 = str_replace(",", ", ", $row['outstanding_lead_ids']);

 


	$emailQueue = new EmailQueue();

	$emailQueue->from_email = Yii::app()->params['adminEmail'];

	$emailQueue->from_name = Yii::app()->name;

	$emailQueue->subject = $var3.", you have ".$var5." visits outstanding.";

	//$emailQueue->to_email = $emailAddress;

	$emailQueue->to_email = 'me@here.co.uk';

	$emailQueue->date_published = new CDbExpression('NOW()');

	$emailQueue->message = Yii::app()->controller->renderPartial('//emails/missed_visits', array(

		'var1' => $var1,

		'var2' => $var2,

		'var3' => $var3,

		'var3' => $var4,

		'var3' => $var5,

		'var6' => $var6,

		), true);


	$emailQueue->save();

	

}	

?>

try this extension

http://www.yiiframework.com/extension/simplemailer

http://www.yiiframework.com/extension/simplemailer

Thanks Rajith, I did look a that a while ago, juSt tried to install it but cant - the commandline is giving me memory issues… I will have to avoid that extension as i have little time, I will try to work out how to get my current code to work, I think I need to invoke the consol command… the data is all in the DB fine, i just cant send it.