test.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?
  2. require("class.phpmailer.php");
  3. $smtp_server = "121.52.212.84"; // SMTP servers
  4. $smtp_auth = true; // turn on SMTP authentication
  5. $smtp_username = "zjh@castertroy.net"; // SMTP username
  6. $smtp_password = "A119328118a"; // SMTP password
  7. $from = "zjh@castertroy.net";
  8. $to = "jinhui.zhu@live.cn";
  9. $subject = "Test Mail";
  10. // send mail via SMTP
  11. $mail = new PHPMailer();
  12. $image_content_id=
  13. $html_message="<html>
  14. <head>
  15. <title>$subject</title>
  16. <style type=\"text/css\"><!--
  17. body { color: black ; font-family: arial, helvetica, sans-serif ; background-color: #A3C5CC }
  18. A:link, A:visited, A:active { text-decoration: underline }
  19. --></style>
  20. </head>
  21. <body>
  22. <table background=\"$background_image_content_id\" width=\"100%\">
  23. <tr>
  24. <td>
  25. <center><h1>$subject</h1></center>
  26. <hr>
  27. <P>Hello ".strtok($to_name," ").",<br><br>
  28. This message is just to let you know that the <a href=\"http://www.phpclasses.org/mimemessage\">MIME E-mail message composing and sending PHP class</a> is working as expected.<br><br>
  29. <center><h2>Here is an image embedded in a message as a separate part:</h2></center>
  30. <center><img src=\"cid:png1\"></center>".
  31. /*
  32. * This example of embedding images in HTML messages is commented out
  33. * because not all mail programs support this method.
  34. *
  35. * <center><h2>Here is an image embedded directly in the HTML:</h2></center>
  36. * <center><img src=\"".$image_data_url."\"></center>
  37. */
  38. "Thank you,<br>
  39. $from_name</p>
  40. </td>
  41. </tr>
  42. </table>
  43. </body>
  44. </html>";
  45. $mail->IsSMTP();
  46. $mail->Host = $smtp_server;
  47. $mail->SMTPAuth = $smtp_auth;
  48. $mail->Username = $smtp_username;
  49. $mail->Password = $smtp_password;
  50. //AddEmbeddedImage(var $path, var $cid, var $name, var $encoding, var $type)
  51. $mail->AddEmbeddedImage('mail.jpg', 'png1', 'mail.jpg','base64',"image/jpg");
  52. $mail->From = $from;
  53. $mail->AddAddress($to);
  54. $mail->IsHTML(true); // send as HTML
  55. $mail->Subject = $subject;
  56. $mail->Body = $html_message;
  57. //$mail->AltBody = $html_message;
  58. if(!$mail->Send())
  59. {
  60. echo "Message was not sent <p>";
  61. echo "Mailer Error: " . $mail->ErrorInfo;
  62. exit;
  63. }
  64. echo "Message has been sent";
  65. ?>