/home/nondinda/domains/nondindaengcity.go.th/public_html/webboard/mail-sending-script.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
<?php
if(!empty($_POST["send"])) {
    require_once (
'phpmailer/class.phpmailer.php');
    
    
$mail = new PHPMailer();
    
$mail->IsSMTP();
    
$mail->SMTPDebug 0;
    
$mail->SMTPAuth TRUE;
    
    
$mail->Port 587;
    
    
$mail->Username "YOUR SMTP USERNAME";
    
$mail->Password "YOUR SMTP PASSWORD";
    
    
$mail->Mailer "smtp";
    
    if (isset(
$_POST["userEmail"])) {
        
$userEmail $_POST["userEmail"];
    }
    if (isset(
$_POST["userName"])) {
        
$userName $_POST["userName"];
    }
    if (isset(
$_POST["subject"])) {
        
$subject $_POST["subject"];
    }
    if (isset(
$_POST["userMessage"])) {
        
$message $_POST["userMessage"];
    }
    
$mail->SetFrom($userEmail$userName);
    
$mail->AddReplyTo($userEmail$userName);
    
$mail->AddAddress("YOUR RECIPIENT EMAIL"); // set recipient email address
    
    
$mail->Subject $subject;
    
$mail->WordWrap 80;
    
$mail->MsgHTML($message);
    
    
$mail->IsHTML(true);
    
    
$mail->SMTPSecure 'tls';
    
$mail->Host 'smtp.gmail.com';
    
    if (! empty(
$_FILES['attachment'])) {
        
$count count($_FILES['attachment']['name']);
        if (
$count 0) {
            
// Attaching multiple files with the email
            
for ($i 0$i $count$i ++) {
                if (! empty(
$_FILES["attachment"]["name"])) {
                    
                    
$tempFileName $_FILES["attachment"]["tmp_name"][$i];
                    
$fileName $_FILES["attachment"]["name"][$i];
                    
$mail->AddAttachment($tempFileName$fileName);
                }
            }
        }
    }
    if (! 
$mail->Send()) {
        
$message "Problem in sending email";
        
$type "error";
    } else {
        
$message "Mail sent successfully";
        
$type "success";
    }
}