Просмотр файла main_files/phpmailer/test/test_callback.php

Размер файла: 2.62Kb
  1. <html>
  2. <head>
  3. <title>PHPMailer Lite - DKIM and Callback Function test</title>
  4. </head>
  5. <body>
  6.  
  7. <?php
  8. /* This is a sample callback function for PHPMailer Lite.
  9. * This callback function will echo the results of PHPMailer processing.
  10. */
  11.  
  12. /* Callback (action) function
  13. * boolean $result result of the send action
  14. * string $to email address of the recipient
  15. * string $cc cc email addresses
  16. * string $bcc bcc email addresses
  17. * string $subject the subject
  18. * string $body the email body
  19. * @return boolean
  20. */
  21. function callbackAction($result, $to, $cc, $bcc, $subject, $body)
  22. {
  23. /*
  24. this callback example echos the results to the screen - implement to
  25. post to databases, build CSV log files, etc., with minor changes
  26. */
  27. $to = cleanEmails($to, 'to');
  28. $cc = cleanEmails($cc[0], 'cc');
  29. $bcc = cleanEmails($bcc[0], 'cc');
  30. echo $result . "\tTo: " . $to['Name'] . "\tTo: " . $to['Email'] . "\tCc: " . $cc['Name'] .
  31. "\tCc: " . $cc['Email'] . "\tBcc: " . $bcc['Name'] . "\tBcc: " . $bcc['Email'] .
  32. "\t" . $subject . "\n\n". $body . "\n";
  33. return true;
  34. }
  35.  
  36. require_once '../PHPMailerAutoload.php';
  37. $mail = new PHPMailer();
  38.  
  39. try {
  40. $mail->isMail();
  41. $mail->setFrom('you@example.com', 'Your Name');
  42. $mail->addAddress('another@example.com', 'John Doe');
  43. $mail->Subject = 'PHPMailer Test Subject';
  44. $mail->msgHTML(file_get_contents('../examples/contents.html'));
  45. // optional - msgHTML will create an alternate automatically
  46. $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
  47. $mail->addAttachment('../examples/images/phpmailer.png'); // attachment
  48. $mail->addAttachment('../examples/images/phpmailer_mini.png'); // attachment
  49. $mail->action_function = 'callbackAction';
  50. $mail->send();
  51. echo "Message Sent OK</p>\n";
  52. } catch (phpmailerException $e) {
  53. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  54. } catch (Exception $e) {
  55. echo $e->getMessage(); //Boring error messages from anything else!
  56. }
  57.  
  58. function cleanEmails($str, $type)
  59. {
  60. if ($type == 'cc') {
  61. $addy['Email'] = $str[0];
  62. $addy['Name'] = $str[1];
  63. return $addy;
  64. }
  65. if (!strstr($str, ' <')) {
  66. $addy['Name'] = '';
  67. $addy['Email'] = $addy;
  68. return $addy;
  69. }
  70. $addyArr = explode(' <', $str);
  71. if (substr($addyArr[1], -1) == '>') {
  72. $addyArr[1] = substr($addyArr[1], 0, -1);
  73. }
  74. $addy['Name'] = $addyArr[0];
  75. $addy['Email'] = $addyArr[1];
  76. $addy['Email'] = str_replace('@', '&#64;', $addy['Email']);
  77. return $addy;
  78. }
  79. ?>
  80. </body>
  81. </html>