Move busui to seperate repository
[bus.git] / extending.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<html>
<head>
<title>Examples using phpmailer</title>
</head>
 
<body bgcolor="#FFFFFF">
 
<h2>Examples using phpmailer</h2>
 
<h3>1. Advanced Example</h3>
<p>
 
This demonstrates sending out multiple email messages with binary attachments
from a MySQL database with multipart/alternative support.<p>
<table cellpadding="4" border="1" width="80%">
<tr>
<td bgcolor="#CCCCCC">
<pre>
require("class.phpmailer.php");
 
$mail = new phpmailer();
 
$mail->From     = "list@example.com";
$mail->FromName = "List manager";
$mail->Host     = "smtp1.example.com;smtp2.example.com";
$mail->Mailer   = "smtp";
 
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query ="SELECT full_name, email,photoFROM employeeWHEREid=$id";
$result=@MYSQL_QUERY($query);
 
while ($row = mysql_fetch_array ($result))
{
    // HTML body
    $body  = "Hello &lt;font size=\"4\"&gt;" . $row["full_name"] . "&lt;/font&gt;, &lt;p&gt;";
    $body .= "&lt;i&gt;Your&lt;/i&gt; personal photograph to this message.&lt;p&gt;";
    $body .= "Sincerely, &lt;br&gt;";
    $body .= "phpmailer List manager";
 
    // Plain text body (for mail clients that cannot read HTML)
    $text_body  = "Hello " . $row["full_name"] . ", \n\n";
    $text_body .= "Your personal photograph to this message.\n\n";
    $text_body .= "Sincerely, \n";
    $text_body .= "phpmailer List manager";
 
    $mail->Body    = $body;
    $mail->AltBody = $text_body;
    $mail->AddAddress($row["email"], $row["full_name"]);
    $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
 
    if(!$mail->Send())
        echo "There has been a mail error sending to " . $row["email"] . "&lt;br&gt;";
 
    // Clear all addresses and attachments for next loop
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
</pre>
</td>
</tr>
</table>
<p>
 
<h3>2. Extending phpmailer</h3>
<p>
 
Extending classes with inheritance is one of the most
powerful features of object-oriented
programming.  It allows you to make changes to the
original class for your
own personal use without hacking the original
classes.  Plus, it is very
easy to do. I've provided an example:
 
<p>
Here's a class that extends the phpmailer class and sets the defaults
for the particular site:<br>
PHP include file: <b>mail.inc.php</b>
<p>
 
<table cellpadding="4" border="1" width="80%">
<tr>
<td bgcolor="#CCCCCC">
<pre>
require("class.phpmailer.php");
 
class my_phpmailer extends phpmailer {
    // Set default variables for all new objects
    var $From     = "from@example.com";
    var $FromName = "Mailer";
    var $Host     = "smtp1.example.com;smtp2.example.com";
    var $Mailer   = "smtp";                         // Alternative to IsSMTP()
    var $WordWrap = 75;
 
    // Replace the default error_handler
    function error_handler($msg) {
        print("My Site Error");
        print("Description:");
        printf("%s", $msg);
        exit;
    }
 
    // Create an additional function
    function do_something($something) {
        // Place your new code here
    }
}
</td>
</tr>
</table>
<br>
 
Now here's a normal PHP page in the site, which will have all the defaults set
above:<br>
Normal PHP file: <b>mail_test.php</b>
<p>
 
<table cellpadding="4" border="1" width="80%">
<tr>
<td bgcolor="#CCCCCC">
<pre>
require("mail.inc.php");
 
// Instantiate your new class
$mail = new my_phpmailer;
 
// Now you only need to add the necessary stuff
$mail->AddAddress("josh@example.com", "Josh Adams");
$mail->Subject = "Here is the subject";
$mail->Body    = "This is the message body";
$mail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip");  // optional name
 
if(!$mail->Send())
{
   echo "There was an error sending the message";
   exit;
}
 
echo "Message was sent successfully";
</pre>
</td>
</tr>
</table>
</p>
 
</body>
</html>