Code syncronized with shipsimu code base
[mailer.git] / inc / classes / third_party / php_mailer / docs / extending.html
diff --git a/inc/classes/third_party/php_mailer/docs/extending.html b/inc/classes/third_party/php_mailer/docs/extending.html
new file mode 100644 (file)
index 0000000..f7c3200
--- /dev/null
@@ -0,0 +1,148 @@
+<html>\r
+<head>\r
+<title>Examples using phpmailer</title>\r
+</head>\r
+\r
+<body bgcolor="#FFFFFF">\r
+\r
+<h2>Examples using phpmailer</h2>\r
+\r
+<h3>1. Advanced Example</h3>\r
+<p>\r
+\r
+This demonstrates sending out multiple email messages with binary attachments\r
+from a MySQL database with multipart/alternative support.<p>\r
+<table cellpadding="4" border="1" width="80%">\r
+<tr>\r
+<td bgcolor="#CCCCCC">\r
+<pre>\r
+require("class.phpmailer.php");\r
+\r
+$mail = new phpmailer();\r
+\r
+$mail->From     = "list@example.com";\r
+$mail->FromName = "List manager";\r
+$mail->Host     = "smtp1.example.com;smtp2.example.com";\r
+$mail->Mailer   = "smtp";\r
+\r
+@MYSQL_CONNECT("localhost","root","password");\r
+@mysql_select_db("my_company");\r
+$query  = "SELECT full_name, email, photo FROM employee WHERE id=$id";\r
+$result = @MYSQL_QUERY($query);\r
+\r
+while ($row = mysql_fetch_array ($result))\r
+{\r
+    // HTML body\r
+    $body  = "Hello &lt;font size=\"4\"&gt;" . $row["full_name"] . "&lt;/font&gt;, &lt;p&gt;";\r
+    $body .= "&lt;i&gt;Your&lt;/i&gt; personal photograph to this message.&lt;p&gt;";\r
+    $body .= "Sincerely, &lt;br&gt;";\r
+    $body .= "phpmailer List manager";\r
+\r
+    // Plain text body (for mail clients that cannot read HTML)\r
+    $text_body  = "Hello " . $row["full_name"] . ", \n\n";\r
+    $text_body .= "Your personal photograph to this message.\n\n";\r
+    $text_body .= "Sincerely, \n";\r
+    $text_body .= "phpmailer List manager";\r
+\r
+    $mail->Body    = $body;\r
+    $mail->AltBody = $text_body;\r
+    $mail->AddAddress($row["email"], $row["full_name"]);\r
+    $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");\r
+\r
+    if(!$mail->Send())\r
+        echo "There has been a mail error sending to " . $row["email"] . "&lt;br&gt;";\r
+\r
+    // Clear all addresses and attachments for next loop\r
+    $mail->ClearAddresses();\r
+    $mail->ClearAttachments();\r
+}\r
+</pre>\r
+</td>\r
+</tr>\r
+</table>\r
+<p>\r
+\r
+<h3>2. Extending phpmailer</h3>\r
+<p>\r
+\r
+Extending classes with inheritance is one of the most\r
+powerful features of object-oriented\r
+programming.  It allows you to make changes to the\r
+original class for your\r
+own personal use without hacking the original\r
+classes.  Plus, it is very\r
+easy to do. I've provided an example:\r
+\r
+<p>\r
+Here's a class that extends the phpmailer class and sets the defaults\r
+for the particular site:<br>\r
+PHP include file: <b>mail.inc.php</b>\r
+<p>\r
+\r
+<table cellpadding="4" border="1" width="80%">\r
+<tr>\r
+<td bgcolor="#CCCCCC">\r
+<pre>\r
+require("class.phpmailer.php");\r
+\r
+class my_phpmailer extends phpmailer {\r
+    // Set default variables for all new objects\r
+    var $From     = "from@example.com";\r
+    var $FromName = "Mailer";\r
+    var $Host     = "smtp1.example.com;smtp2.example.com";\r
+    var $Mailer   = "smtp";                         // Alternative to IsSMTP()\r
+    var $WordWrap = 75;\r
+\r
+    // Replace the default error_handler\r
+    function error_handler($msg) {\r
+        print("My Site Error");\r
+        print("Description:");\r
+        printf("%s", $msg);\r
+        exit;\r
+    }\r
+\r
+    // Create an additional function\r
+    function do_something($something) {\r
+        // Place your new code here\r
+    }\r
+}\r
+</td>\r
+</tr>\r
+</table>\r
+<br>\r
+\r
+Now here's a normal PHP page in the site, which will have all the defaults set\r
+above:<br>\r
+Normal PHP file: <b>mail_test.php</b>\r
+<p>\r
+\r
+<table cellpadding="4" border="1" width="80%">\r
+<tr>\r
+<td bgcolor="#CCCCCC">\r
+<pre>\r
+require("mail.inc.php");\r
+\r
+// Instantiate your new class\r
+$mail = new my_phpmailer;\r
+\r
+// Now you only need to add the necessary stuff\r
+$mail->AddAddress("josh@example.com", "Josh Adams");\r
+$mail->Subject = "Here is the subject";\r
+$mail->Body    = "This is the message body";\r
+$mail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip");  // optional name\r
+\r
+if(!$mail->Send())\r
+{\r
+   echo "There was an error sending the message";\r
+   exit;\r
+}\r
+\r
+echo "Message was sent successfully";\r
+</pre>\r
+</td>\r
+</tr>\r
+</table>\r
+</p>\r
+\r
+</body>\r
+</html>\r