1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: $plugin_is_filter = 800 | CLASS_PLUGIN;
11: $plugin_description = gettext("Zenphoto outgoing mail handler based on the <em>PHPMailer</em> class mailing facility.");
12: $plugin_author = "Stephen Billard (sbillard)";
13: $plugin_disable = (zp_has_filter('sendmail') && !extensionEnabled('PHPMailer')) ? sprintf(gettext('Only one Email handler plugin may be enabled. <a href="#%1$s"><code>%1$s</code></a> is already enabled.'), stripSuffix(get_filterScript('sendmail'))) : '';
14:
15: $option_interface = 'zp_PHPMailer';
16:
17: if ($plugin_disable) {
18: enableExtension('PHPMailer', 0);
19: } else {
20: zp_register_filter('sendmail', 'zenphoto_PHPMailer');
21: }
22:
23: 24: 25: 26:
27: class zp_PHPMailer {
28:
29: 30: 31: 32: 33:
34: function __construct() {
35: setOptionDefault('PHPMailer_mail_protocol', 'sendmail');
36: setOptionDefault('PHPMailer_server', '');
37: setOptionDefault('PHPMailer_pop_port', '110');
38: setOptionDefault('PHPMailer_smtp_port', '25');
39: setOptionDefault('PHPMailer_user', '');
40: setOptionDefault('PHPMailer_password', '');
41: setOptionDefault('PHPMailer_secure', 0);
42: if (getOption('PHPMailer_secure') == 1)
43: setOption('PHPMailer_secure', 'ssl');
44: }
45:
46: 47: 48: 49: 50:
51: function getOptionsSupported() {
52: return array(gettext('Mail protocol') => array('key' => 'PHPMailer_mail_protocol', 'type' => OPTION_TYPE_RADIO,
53: 'buttons' => array('POP3' => 'pop3', 'SMTP' => 'smtp', 'SendMail' => 'sendmail'),
54: 'desc' => gettext('Select the mail protocol you wish to be used.')),
55: gettext('Outgoing mail server') => array('key' => 'PHPMailer_server', 'type' => OPTION_TYPE_TEXTBOX,
56: 'desc' => gettext('Outgoing mail server.')),
57: gettext('Secure mail') => array('key' => 'PHPMailer_secure', 'type' => OPTION_TYPE_RADIO,
58: 'buttons' => array(gettext('no') => 0, gettext('SSL') => 'ssl', gettext('TLS') => 'tls'),
59: 'desc' => gettext('Set to use a secure protocol.')),
60: gettext('Mail user') => array('key' => 'PHPMailer_user', 'type' => OPTION_TYPE_TEXTBOX,
61: 'desc' => gettext('<em>User ID</em> for mail server.')),
62: gettext('Mail password') => array('key' => 'PHPMailer_password', 'type' => OPTION_TYPE_CUSTOM,
63: 'desc' => gettext('<em>Password</em> for mail server.')),
64: gettext('POP port') => array('key' => 'PHPMailer_pop_port', 'type' => OPTION_TYPE_TEXTBOX,
65: 'desc' => gettext('POP port number.')),
66: gettext('SMTP port') => array('key' => 'PHPMailer_smtp_port', 'type' => OPTION_TYPE_TEXTBOX,
67: 'desc' => gettext('SMTP port number.'))
68: );
69: }
70:
71: 72: 73: 74: 75: 76:
77: function handleOption($option, $currentValue) {
78: if ($option == "PHPMailer_password") {
79: ?>
80: <input type="password" size="40" name="<?php echo $option; ?>" style="width: 338px" value="<?php echo html_encode($currentValue); ?>" />
81: <?php
82: }
83: }
84:
85: }
86:
87: function zenphoto_PHPMailer($msg, $email_list, $subject, $message, $from_mail, $from_name, $cc_addresses, $replyTo) {
88: require_once(dirname(__FILE__) . '/PHPMailer/PHPMailerAutoload.php');
89: switch (getOption('PHPMailer_mail_protocol')) {
90: case 'pop3':
91: $pop = new POP3();
92: $authorized = $pop->Authorise(getOption('PHPMailer_server'), getOption('PHPMailer_pop_port'), 30, getOption('PHPMailer_user'), getOption('PHPMailer_password'), 0);
93: $mail = new PHPMailer();
94: $mail->IsSMTP();
95: $mail->Port = getOption('PHPMailer_smtp_port');
96: $mail->Host = getOption('PHPMailer_server');
97: break;
98: case 'smtp':
99: $mail = new PHPMailer();
100: $mail->SMTPAuth = true;
101: $mail->IsSMTP();
102: $mail->Username = getOption('PHPMailer_user');
103: $mail->Password = getOption('PHPMailer_password');
104: $mail->Host = getOption('PHPMailer_server');
105: $mail->Port = getOption('PHPMailer_smtp_port');
106: break;
107: case 'sendmail':
108: $mail = new PHPMailer();
109: $mail->IsSendmail();
110: break;
111: }
112: $mail->SMTPSecure = getOption('PHPMailer_secure');
113: $mail->CharSet = 'UTF-8';
114: $mail->From = $from_mail;
115: $mail->FromName = $from_name;
116: $mail->Subject = $subject;
117: $mail->Body = $message;
118: $mail->AltBody = '';
119: $mail->IsHTML(false);
120:
121: foreach ($email_list as $to_name => $to_mail) {
122: if (is_numeric($to_name)) {
123: $mail->AddAddress($to_mail);
124: } else {
125: $mail->AddAddress($to_mail, $to_name);
126: }
127: }
128: if (count($cc_addresses) > 0) {
129: foreach ($cc_addresses as $cc_name => $cc_mail) {
130: $mail->AddCC($cc_mail);
131: }
132: }
133: if ($replyTo) {
134: $names = array_keys($replyTo);
135: $mail->AddReplyTo(array_shift($replyTo), array_shift($names));
136: }
137: if (!$mail->Send()) {
138: if (!empty($msg))
139: $msg .= '<br />';
140: $msg .= sprintf(gettext('<code>PHPMailer</code> failed to send <em>%1$s</em>. ErrorInfo:%2$s'), $subject, $mail->ErrorInfo);
141: }
142: return $msg;
143: }
144: ?>
145: