/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to includes/PHPMailer-Lite_v5.1/test/test_callback.php

  • Committer: Suren A. Chilingaryan
  • Date: 2011-01-26 02:48:39 UTC
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: csa@dside.dyndns.org-20110126024839-nv6qp2ie9stmd2dn
Support of Appled devices by Toni Pirhonen

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *   bool    $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
  this callback example echos the results to the screen - implement to
 
24
  post to databases, build CSV log files, etc., with minor changes
 
25
  */
 
26
  $to  = cleanEmails($to,'to');
 
27
  $cc  = cleanEmails($cc[0],'cc');
 
28
  $bcc = cleanEmails($bcc[0],'cc');
 
29
  echo $result . "\tTo: "  . $to['Name'] . "\tTo: "  . $to['Email'] . "\tCc: "  . $cc['Name'] . "\tCc: "  . $cc['Email'] . "\tBcc: "  . $bcc['Name'] . "\tBcc: "  . $bcc['Email'] . "\t"  . $subject . "<br />\n";
 
30
  return true;
 
31
}
 
32
 
 
33
$testLite = false;
 
34
 
 
35
if ($testLite) {
 
36
  require_once '../class.phpmailer-lite.php';
 
37
  $mail = new PHPMailerLite();
 
38
} else {
 
39
  require_once '../class.phpmailer.php';
 
40
  $mail = new PHPMailer();
 
41
}
 
42
 
 
43
try {
 
44
  $mail->IsMail(); // telling the class to use SMTP
 
45
  $mail->SetFrom('you@yourdomain.com', 'Your Name');
 
46
  $mail->AddAddress('another@yourdomain.com', 'John Doe');
 
47
  $mail->Subject = 'PHPMailer Lite Test Subject via Mail()';
 
48
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
 
49
  $mail->MsgHTML(file_get_contents('contents.html'));
 
50
  $mail->AddAttachment('images/phpmailer.gif');      // attachment
 
51
  $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
 
52
  $mail->action_function = 'callbackAction';
 
53
  $mail->Send();
 
54
  echo "Message Sent OK</p>\n";
 
55
} catch (phpmailerException $e) {
 
56
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
 
57
} catch (Exception $e) {
 
58
  echo $e->getMessage(); //Boring error messages from anything else!
 
59
}
 
60
 
 
61
function cleanEmails($str,$type) {
 
62
  if ($type == 'cc') {
 
63
    $addy['Email'] = $str[0];
 
64
    $addy['Name']  = $str[1];
 
65
    return $addy;
 
66
  }
 
67
  if (!strstr($str, ' <')) {
 
68
    $addy['Name']  = '';
 
69
    $addy['Email'] = $addy;
 
70
    return $addy;
 
71
  }
 
72
  $addyArr = explode(' <', $str);
 
73
  if (substr($addyArr[1],-1) == '>') {
 
74
    $addyArr[1] = substr($addyArr[1],0,-1);
 
75
  }
 
76
  $addy['Name']  = $addyArr[0];
 
77
  $addy['Email'] = $addyArr[1];
 
78
  $addy['Email'] = str_replace('@', '&#64;', $addy['Email']);
 
79
  return $addy;
 
80
}
 
81
 
 
82
?>
 
83
</body>
 
84
</html>