-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.php
95 lines (71 loc) · 2.38 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/*
* Try this sample code to try DKIM and/or Domain Keys signature headers in your e-mails.
*
* Uncomment the mail() lines to actually test the sending of e-mail.
*
* Note that Domain Keys is currently NOT usable with PHP's mail() function (see the
* class file for more information). So Domain Keys is disabled by default, enable it in
* the options if you need it.
*/
// YOUR E-MAIL
$to = '[email protected]';
$subject = 'My subject';
$headers =
'MIME-Version: 1.0
From: "Sender" <[email protected]>
Content-type: text/html; charset=utf8';
$message =
'<html>
<header></header>
<body>
Hello, this a DKIM test e-mail
</body>
</html>';
// 1) YOU USUALLY DID :
// mail($to, $subject, $message, $headers);
// 2) NOW YOU WILL DO (after setting up the config file and your DNS records) :
// Make sure linefeeds are in CRLF format - it is essential for signing
$message = preg_replace('/(?<!\r)\n/', "\r\n", $message);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
require_once 'mail-signature.class.php';
require_once 'mail-signature.config.php';
$signature = new mail_signature(
MAIL_RSA_PRIV,
MAIL_RSA_PASSPHRASE,
MAIL_DOMAIN,
MAIL_SELECTOR
);
$signed_headers = $signature -> get_signed_headers($to, $subject, $message, $headers);
// mail($to, $subject, $message, $signed_headers.$headers);
// 3) OR USE OPTIONS TO ADD SOME FLAVOR :
$message = preg_replace('/(?<!\r)\n/', "\r\n", $message);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
$options = array(
'use_dkim' => false,
'use_domainKeys' => true,
'identity' => MAIL_IDENTITY,
// if you prefer simple canonicalization (though the default "relaxed"
// is recommended)
'dkim_body_canonicalization' => 'simple',
'dk_canonicalization' => 'nofws',
// if you want to sign the mail on a different list of headers than the
// default one (see class constructor). Case-insensitive.
'signed_headers' => array(
'message-Id',
'Content-type',
'To',
'subject'
)
);
require_once 'mail-signature.class.php';
require_once 'mail-signature.config.php';
$signature = new mail_signature(
MAIL_RSA_PRIV,
MAIL_RSA_PASSPHRASE,
MAIL_DOMAIN,
MAIL_SELECTOR,
$options
);
$signed_headers = $signature -> get_signed_headers($to, $subject, $message, $headers);
// mail($to, $subject, $message, $signed_headers.$headers);