PageRenderTime 21ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/experimental/mail/Mail.php

http://zoop.googlecode.com/
PHP | 73 lines | 58 code | 13 blank | 2 comment | 4 complexity | dda728d6f5f1a44a7f2701c0217c952f MD5 | raw file
 1<?php
 2//	these should really call a common function
 3//	or there shoudl be just one function with another paramater or something
 4class Mail
 5{
 6	function text($to, $toName, $from, $fromName, $subject, $body)
 7	{
 8		$mail = new mailer();
 9		if( defined('mail_from') )
10		{
11			$mail->From = mail_from;
12			$mail->AddReplyTo($from, $fromName);
13		}
14		else
15		{
16			$mail->From = $from;
17		}
18		
19		$mail->FromName = $fromName;
20		
21		$mail->AddAddress($to, $toName);
22
23		$mail->IsHTML(false);
24
25		$mail->Subject = $subject;
26		$mail->Body    = $body;
27		
28		$result = $mail->Send(); 
29		
30		if(!$result)
31		   trigger_error("Message could not be sent. Mailer Error: " . $mail->ErrorInfo);
32	}
33	
34	function html($to, $toName, $from, $fromName, $subject, $body)
35	{
36		$mail = new mailer();
37		
38		if( defined('mail_from') )
39		{
40			$mail->From = mail_from;
41			$mail->AddReplyTo($from, $fromName);
42		}
43		else
44		{
45			$mail->From = $from;
46		}
47		
48		$mail->FromName = $fromName;
49		
50		$mail->IsHTML(true);
51		$mail->Subject = $subject;
52		$mail->Body    = $body;
53
54		switch(gettype($to))
55		{
56			case 'string':
57				$mail->AddAddress($to, $toName);
58				break;
59			case 'array':
60				foreach($to as $toKey => $thisTo)
61					$mail->AddAddress($thisTo, $toName[$toKey]);
62				break;
63			default:
64				trigger_error('invalid type for address field');
65		}			
66		
67		
68		if(!$mail->Send())
69		{
70		   trigger_error("Message could not be sent. Mailer Error: " . $mail->ErrorInfo);
71		}
72	}
73}