source: hadoop-register/etc/phpMailer/examples/index.html @ 79

Last change on this file since 79 was 57, checked in by jazz, 16 years ago
  • 第一版 Hadoop 叢集之帳號申請網頁 by Wade
File size: 3.0 KB
Line 
1<p>The example file &quot;test_mail.php&quot; contents include:</p>
2<div style="width: 600px; background-color: #CCCCCC;">
3<code>
4&lt;?php<br>
5<br>
6include_once('../class.phpmailer.php');<br>
7<br>
8$mail    = new PHPMailer();<br>
9<br>
10$body    = $mail->getFile('contents.html');<br>
11<br>
12$body    = eregi_replace("[\]",'',$body);<br>
13$subject = eregi_replace("[\]",'',$subject);<br>
14<br>
15$mail->From     = "name@yourdomain.com";<br>
16$mail->FromName = "First Last";<br>
17<br>
18$mail->Subject = "PHPMailer Test Subject";<br>
19<br>
20$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test<br>
21<br>
22$mail->MsgHTML($body);<br>
23<br>
24$mail->AddAddress("whoto@otherdomain.com", "John Doe");<br>
25<br>
26if(!$mail->Send()) {<br>
27  echo 'Failed to send mail';<br>
28} else {<br>
29  echo 'Mail sent';<br>
30}<br>
31<br>
32?&gt;
33</code>
34</div>
35<br>
36Although you could use full compabitility with PHPMailer 1.7.3, this example
37shows how to use the new features. If you view 'contents.html', you will note
38that there is a background image used in the &lt;body tag as well as an image used
39with a regular &lt;img tag. Here&#39;s what the HTML file looks like:<br>
40<br>
41<div style="width: 600px; background-color: #CCCCCC;">
42<code>
43&lt;body background="images/bkgrnd.gif" style="margin: 0px;"&gt;<br>
44&lt;div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;"&gt;<br>
45&lt;div align="center"&gt;&lt;img src="images/phpmailer.gif" style="height: 90px; width: 340px"&gt;&lt;/div&gt;&lt;br&gt;<br>
46&lt;br&gt;<br>
47&nbsp;This is a test of PHPMailer v2.0.0 rc1.&lt;br&gt;<br>
48&lt;br&gt;<br>
49This particular example uses &lt;strong&gt;HTML&lt;/strong&gt;, with a &lt;div&gt; tag and inline&lt;br&gt;<br>
50styles.&lt;br&gt;<br>
51&lt;br&gt;<br>
52Also note the use of the PHPMailer at the top with no specific code to handle<br>
53including it in the body of the email.&lt;/div&gt;<br>
54&lt;/body&gt;<br>
55</code>
56</div>
57<br>
58A few things to notice in the PHP script that generates the email:
59<ul>
60  <li>the use of $mail-&gt;AltBody is completely optional. If not used, PHPMailer
61  will use the HTML text with htmlentities().</li>
62  <li>the background= and &lt;img src= images were processed without any directives
63  or methods from the PHP script</li>
64  <li>there is no specific code to define the image type ... that is handled
65  automatically by PHPMailer when it parses the images</li>
66  <li>we are using a new class method '$mail->MsgHTML($body)' ... that is what will handle the parsing of the images and creating the AltBody text</li>
67</ul>
68<p>Of course, you can still use PHPMailer the same way you have in the past.
69That provides full compatibility with all existing scripts, while new scripts
70can take advantage of the new features.</p>
71<p>Modify test_mail.php now with your own email address and try it out.</p>
72To see what the email SHOULD look like in your HTML compatible email viewer: <a href="contents.html">click here</a><br>
73
Note: See TracBrowser for help on using the repository browser.