-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestmail.php
executable file
·80 lines (58 loc) · 1.76 KB
/
testmail.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
<?php
ob_start();
// debug
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// PEAR Mail
require( dirname( __FILE__) . '/Mail.php' );
require( dirname( __FILE__) . '/inc/smtp.php' );
require( dirname( __FILE__) . '/inc/mime.php' );
/** @var array $config */
$config = json_decode( file_get_contents( "config.json" ), true );
$from = $config[ 'username' ];
$to = $config[ 'to' ];
$subject = $config[ 'title' ];
$crlf = "\n";
/**
* HTML body
*/
// Creating the Mime message
/** @var object $mime */
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody( 'Please use HTML client' );
$mime->setHTMLBody( file_get_contents( dirname( __FILE__) . '/pub/mail.html' ) );
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject,
);
$headers = $mime->headers($headers);
echo "\n\n". 'HEADERS:' . "\n\n";
var_dump( $headers );
$smtp = Mail::factory('smtp', array(
'host' => $config[ 'host' ],
'port' => $config[ 'port' ],
'auth' => 'LOGIN',
'username' => $config[ 'username' ],
'password' => $config[ 'password' ],
'debug' => true,
'pipelining' => true
));
echo "\n\n" . 'SERVER DEBUG:' . "\n\n";
// Send the mail
if (PEAR::isError($smtp)) {
echo $smtp->getMessage() . "\n" . $smtp->getUserInfo() . "\n";
die();
}
$mail = $smtp->send( $to, $headers, $mime->get() );
if (PEAR::isError($mail)) {
echo("Email not sent. " .$mail->getMessage() ."\n");
} else {
echo("Email sent!"."\n");
}
/** @var strint $output */
$output = nl2br( htmlspecialchars( ob_get_contents() ) );
ob_end_clean();
echo $output;