/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to includes/PHPMailer-Lite_v5.1/docs/extending.html

  • Committer: Suren A. Chilingaryan
  • Date: 2011-01-26 02:48:39 UTC
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: csa@dside.dyndns.org-20110126024839-nv6qp2ie9stmd2dn
Support of Appled devices by Toni Pirhonen

Show diffs side-by-side

added added

removed removed

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