[57] | 1 | <p>The example file "test_mail.php" contents include:</p> |
---|
| 2 | <div style="width: 600px; background-color: #CCCCCC;"> |
---|
| 3 | <code> |
---|
| 4 | <?php<br> |
---|
| 5 | <br> |
---|
| 6 | include_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> |
---|
| 26 | if(!$mail->Send()) {<br> |
---|
| 27 | echo 'Failed to send mail';<br> |
---|
| 28 | } else {<br> |
---|
| 29 | echo 'Mail sent';<br> |
---|
| 30 | }<br> |
---|
| 31 | <br> |
---|
| 32 | ?> |
---|
| 33 | </code> |
---|
| 34 | </div> |
---|
| 35 | <br> |
---|
| 36 | Although you could use full compabitility with PHPMailer 1.7.3, this example |
---|
| 37 | shows how to use the new features. If you view 'contents.html', you will note |
---|
| 38 | that there is a background image used in the <body tag as well as an image used |
---|
| 39 | with a regular <img tag. Here's what the HTML file looks like:<br> |
---|
| 40 | <br> |
---|
| 41 | <div style="width: 600px; background-color: #CCCCCC;"> |
---|
| 42 | <code> |
---|
| 43 | <body background="images/bkgrnd.gif" style="margin: 0px;"><br> |
---|
| 44 | <div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;"><br> |
---|
| 45 | <div align="center"><img src="images/phpmailer.gif" style="height: 90px; width: 340px"></div><br><br> |
---|
| 46 | <br><br> |
---|
| 47 | This is a test of PHPMailer v2.0.0 rc1.<br><br> |
---|
| 48 | <br><br> |
---|
| 49 | This particular example uses <strong>HTML</strong>, with a <div> tag and inline<br><br> |
---|
| 50 | styles.<br><br> |
---|
| 51 | <br><br> |
---|
| 52 | Also note the use of the PHPMailer at the top with no specific code to handle<br> |
---|
| 53 | including it in the body of the email.</div><br> |
---|
| 54 | </body><br> |
---|
| 55 | </code> |
---|
| 56 | </div> |
---|
| 57 | <br> |
---|
| 58 | A few things to notice in the PHP script that generates the email: |
---|
| 59 | <ul> |
---|
| 60 | <li>the use of $mail->AltBody is completely optional. If not used, PHPMailer |
---|
| 61 | will use the HTML text with htmlentities().</li> |
---|
| 62 | <li>the background= and <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. |
---|
| 69 | That provides full compatibility with all existing scripts, while new scripts |
---|
| 70 | can take advantage of the new features.</p> |
---|
| 71 | <p>Modify test_mail.php now with your own email address and try it out.</p> |
---|
| 72 | To see what the email SHOULD look like in your HTML compatible email viewer: <a href="contents.html">click here</a><br> |
---|
| 73 | |
---|