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
|
<?php error_reporting(E_ALL); ini_set('display_errors', 0);
require_once dirname(__DIR__). '/vendor/dapphp/securimage/securimage.php'; require_once dirname(__DIR__). '/vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$image = new Securimage(); if ($image->check($_POST['captcha_code']) == true) { //echo "Correct!"; //exit;
$mail = new PHPMailer(true); // Passing `true` enables exceptions try { $x_mail = new PHPMailer(); //Server settings // $mail->SMTPDebug = 2; // Enable verbose debug output // $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'localhost'; // Specify main and backup SMTP servers // $mail->SMTPAuth = true; // Enable SMTP authentication // $mail->Username = '5dad06ab71a26f'; // SMTP username // $mail->Password = '9c7615563f25fe'; // SMTP password // $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted // $mail->Port = 465; // TCP port to connect to $mail->CharSet = 'UTF-8';
//Recipients $mail->setFrom('lions@lionsclubs.org.hk', '國際獅子總會中國港澳三0三區'); $mail->addAddress('lions@lionsclubs.org.hk', ''); // Add a recipient // $mail->addAddress('recipient@example.com'); // Name is optional // $mail->addReplyTo('replyto@example.com', 'Information'); // $mail->addCC('cc@example.com'); // $mail->addBCC('bcc@example.com');
//Attachments // $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = '剛剛接收到一個來自 '.htmlspecialchars($_POST['name']).' 網站上的查詢'; $mail->Body = "<p>姓名: ".htmlspecialchars($_POST['name'])." ".htmlspecialchars($_POST['gen'])."</p> <p>電郵: ".htmlspecialchars($_POST['email'])."</p> <p>主題: ".htmlspecialchars($_POST['subject'])."</p> <p>内容: ".nl2br(htmlspecialchars($_POST['content']))."</p>"; // $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { //echo "Message sent!"; header('Location: contacts.php');
} } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; }
} else { echo "Sorry, wrong code."; } ?>
|