3
<title>PHPMailer Lite - DKIM and Callback Function test</title>
8
/* This is a sample callback function for PHPMailer Lite.
9
* This callback function will echo the results of PHPMailer processing.
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
21
function callbackAction ($result, $to, $cc, $bcc, $subject, $body) {
23
this callback example echos the results to the screen - implement to
24
post to databases, build CSV log files, etc., with minor changes
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";
36
require_once '../class.phpmailer-lite.php';
37
$mail = new PHPMailerLite();
39
require_once '../class.phpmailer.php';
40
$mail = new PHPMailer();
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';
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!
61
function cleanEmails($str,$type) {
63
$addy['Email'] = $str[0];
64
$addy['Name'] = $str[1];
67
if (!strstr($str, ' <')) {
69
$addy['Email'] = $addy;
72
$addyArr = explode(' <', $str);
73
if (substr($addyArr[1],-1) == '>') {
74
$addyArr[1] = substr($addyArr[1],0,-1);
76
$addy['Name'] = $addyArr[0];
77
$addy['Email'] = $addyArr[1];
78
$addy['Email'] = str_replace('@', '@', $addy['Email']);