Subversion Repositories web_pages

Rev

Rev 5 | Rev 7 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line 108... Line 108...
108
                $message .= "{$field['label']}: " . htmlspecialchars($_POST[$field['name']]) . "\n";
108
                $message .= "{$field['label']}: " . htmlspecialchars($_POST[$field['name']]) . "\n";
109
            }
109
            }
110
        }
110
        }
111
 
111
 
112
        // Prepare to send email using PHPMailer
112
        // Prepare to send email using PHPMailer
113
        $mail = new PHPMailer();
113
        $mail = new PHPMailer(true);
-
 
114
 
114
        try {
115
        try {
115
            if ($config['debug']) {
116
            // Server settings
116
                $mail->SMTPDebug = 2; // Enable verbose debug output
-
 
117
            }
-
 
118
            $mail->isSMTP();
117
            $mail->isSMTP();
119
            $mail->SMTPOptions = array(
-
 
120
                'ssl' => array(
-
 
121
                    'verify_peer' => false,
-
 
122
                    'verify_peer_name' => false,
-
 
123
                    'allow_self_signed' => true
-
 
124
                )
-
 
125
            );
-
 
126
            $mail->Host = $config['smtp_host'];
118
            $mail->Host = $config['smtp_host'];
127
            $mail->SMTPAuth = true;
119
            $mail->SMTPAuth = true;
128
            $mail->Username = $config['smtp_username'];
120
            $mail->Username = $config['smtp_username'];
129
            $mail->Password = $config['smtp_password'];
121
            $mail->Password = $config['smtp_password'];
130
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
122
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
131
            $mail->Port = $config['smtp_port'];
123
            $mail->Port = $config['smtp_port'];
-
 
124
 
-
 
125
            // Set the sender's email address from the form
-
 
126
            if (!empty($_POST['requestor_email']) && !empty($_POST['requestor_name'])) {
-
 
127
                $mail->setFrom($_POST['requestor_email'], $_POST['requestor_name']);
-
 
128
            } else {
132
            $mail->setFrom($config['from'], $config['from_name']);
129
                $mail->setFrom($config['from'], $config['from_name']);
-
 
130
            }
-
 
131
 
-
 
132
            // Add recipient
133
            $mail->addAddress($config['to']);
133
            $mail->addAddress($config['to']);
134
            if (!empty($config['bcc'])) {
134
            if (!empty($config['bcc'])) {
135
                $bccs = explode(',', $config['bcc']);
135
                $bccs = explode(',', $config['bcc']);
136
                foreach ($bccs as $bcc) {
136
                foreach ($bccs as $bcc) {
137
                    $mail->addBCC($bcc);
137
                    $mail->addBCC($bcc);
138
                }
138
                }
139
            }
139
            }
-
 
140
 
-
 
141
            // Add reply-to address
140
            if (!empty($_POST['requestor_email']) && !empty($_POST['requestor_name'])) {
142
            if (!empty($_POST['requestor_email']) && !empty($_POST['requestor_name'])) {
141
                $mail->AddReplyTo($_POST['requestor_email'], $_POST['requestor_name']);
143
                $mail->AddReplyTo($_POST['requestor_email'], $_POST['requestor_name']);
142
            }
144
            }
143
 
145
 
-
 
146
            // Email subject and body
144
            $mail->Subject = htmlspecialchars($_POST['short_description']);
147
            $mail->Subject = htmlspecialchars($_POST['short_description']);
145
            $mail->Body = $message;
148
            $mail->Body = $message;
146
 
149
 
147
            // Attach files if any
150
            // Attach files if any
148
            if (!empty($attachments)) {
151
            if (!empty($attachments)) {
Line 155... Line 158...
155
                            echo "Processing Attachment.<br />";
158
                            echo "Processing Attachment.<br />";
156
                            echo $attachments['name'][$i];
159
                            echo $attachments['name'][$i];
157
                        }
160
                        }
158
                        $mail->addAttachment($attachments['tmp_name'][$i], $attachments['name'][$i]);
161
                        $mail->addAttachment($attachments['tmp_name'][$i], $attachments['name'][$i]);
159
                    }
162
                    }
160
                } else {
-
 
161
                    $mail->addAttachment($attachments['tmp_name'], $attachments['name']);
-
 
162
                }
163
                }
163
            }
164
            }
164
 
165
 
-
 
166
            // Send the email
165
            $mail->send();
167
            $mail->send();
166
            $result = $config['success_message'];
168
            echo $config['success_message'];
167
        } catch (Exception $e) {
169
        } catch (Exception $e) {
168
            $result = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
170
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
169
            $result_error = true;
-
 
170
        }
171
        }
171
    }
172
    }
172
}
173
}
173
?>
174
?>
174
 
175