-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
161 lines (138 loc) · 6.32 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Formularz kontaktowy</title>
<script src="jqvalidation/lib/jquery.js"></script>
<script src="jqvalidation/dist/jquery.validate.js"></script>
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/skrypty.js"></script>
<style>
.error{
color:red;
}
.noerror{
color:green;
}
</style>
</head>
<body>
<div class="container">
<?php
/*
if(!empty($_POST)){
foreach ($_POST as $key=>$value){
echo $key.'='.$value."<br>";
}
}
*/
require 'phpmailer/PHPMailerAutoload.php';
function wyslij($im,$naz,$mail,$tem,$wiad){
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
/*$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; */ // TCP port to connect to
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '-------'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//$mail->setFrom($mail,$im.' '.$naz);
//$mail->addReplyTo($mail,$im.' '.$naz);
//$mail->setFrom('[email protected]','Imie Nazwisko');
//$mail->addReplyTo($mail,$im.' '.$naz);
$mail->addAddress('[email protected]', 'Dominik Panas'); // Add a recipient
$mail->addAddress('[email protected]','Dominik Panas');
$mail->isHTML(true); // Set email format to HTML
$mail -> charSet = "UTF-8";
$mail->Subject = $tem;
$mail->Body = $wiad;
//=============Obejście problemu z wysłaniem z WAMPA=========
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//====================================================
$mmsg="";
if(!$mail->send()) {
$mmsg = 'Nie wysłano wiadomości.<br>';
$mmsg .= 'Błąd Mailera: '.$mail->ErrorInfo;
$mclass= 'alert-danger';
} else {
$mmsg = 'Wiadomość wysłana';
$mclass= 'alert-success';
}
echo '<div class="alert '.$mclass.'">'.$mmsg.'</div>';
unset($mail);
}
$klasa_imie_err = "";
$klasa_nazwisko_err = "";
if(!empty($_POST)){
$err=false;
$msg = '';
if (ctype_alpha($_POST['imie'])==false){
$msg .='Imię zawiera niepoprawne znaki! <br>';
$err=true;
$klasa_imie_err = "error";
}
if (ctype_alpha($_POST['nazwisko'])==false){
$msg .='Nazwisko zawiera niepoprawne znaki! <br>';
$err=true;
$klasa_nazwisko_err = "error";
}
if($err == true) echo '<div class="alert alert-danger">
<strong>Błąd!</strong> '.$msg.'</div>';
else {
$wiadomosc = '
<p>Nadawca: '.$_POST['imie'].' '.$_POST['nazwisko'].'</p>
<p>Email: '.$_POST['email'].'</p>
<br>
<p>'.strip_tags($_POST['wiadomosc']).'</p>
<br>
<br>
<p style="font-style:italic;font-weight:bold">Wiadomość wysłana z formularza kontaktowego<p>
';
wyslij($_POST['imie'],$_POST['nazwisko'],$_POST['email'],strip_tags($_POST['temat']),$wiadomosc);
//wyslij('Bolek','Lolek','[email protected]','temat','wiadomosc');
}
}
?>
<div class="col-lg-8 col-lg-offset-2">
<form class="formkontakt" id="formularzkontaktowy" method="post" >
<fieldset>
<legend>Formularz kontaktowy</legend>
<div class="form-group">
<label for="cimie">Imię (wymagane)</label>
<input id="cimie" name="imie" type="text" class="form-control input-lg <?php echo $klasa_imie_err ?>" value="<?php echo isset($_POST['imie']) ?$_POST['imie'] :"" ?>">
</div>
<div class="form-group">
<label for="cnazwisko">Nazwisko (wymagane)</label>
<input id="cnazwisko" name="nazwisko" type="text" class="form-control input-lg <?php echo $klasa_nazwisko_err ?>" value="<?php echo isset($_POST['nazwisko']) ?$_POST['nazwisko'] :"" ?>">
</div>
<div class="form-group">
<label for="cemail">E-Mail (wymagany)</label>
<input id="cemail" name="email" type="email" class="form-control input-lg" value="<?php echo isset($_POST['email']) ?$_POST['email'] :"" ?>">
</div>
<div class="form-group">
<label for="ctemat">Temat (wymagany)</label>
<input id="ctemat" name="temat" type="text" class="form-control input-lg" value="<?php echo isset($_POST['temat']) ?$_POST['temat'] :"" ?>">
</div>
<div class="form-group">
<label for="cwiadomosc">Wiadomość (wymagana)</label>
<textarea id="cwiadomosc" name="wiadomosc" class="form-control"><?php echo isset($_POST['wiadomosc']) ?$_POST['wiadomosc'] :"" ?></textarea>
</div>
<button class="submit btn btn-primary" type="submit" value="Wyślij">Wyślij</button>
</fieldset>
</form>
</div>
</div>
</body>
</html>