· 11 years ago · Jun 19, 2015, 02:10 AM
1<?php
2
3
4require 'PhpMailer/PHPMailerAutoload.php';
5
6$name = $_POST['name'];
7$email = $_POST["email"];
8$phone = $_POST['phone'];
9$subject = $_POST['subject'];
10$comments = $_POST['comments'];
11
12$mail = new PHPMailer();
13$mail->isSMTP();
14$mail->SMTPDebug = 2;
15$mail->Debugoutput = 'html';
16$mail->Host = 'smtp.gmail.com';
17$mail->Port = 587;
18$mail->SMTPSecure = 'tls';
19
20$mail->SMTPAuth = true;
21$mail->Username = '******.******@gmail.com';
22$mail->Password = '*******';
23
24$mail->AddReplyTo('******.******@gmail.com');
25$mail->AddAddress('*********@gmail.com');
26$mail->SetFrom('*****.*******@gmail.com');
27$mail->Subject = $_POST['subject'];
28$mail->Body = "You have been contacted by $name with regards to $subject, their additional message is as follows." . PHP_EOL . PHP_EOL . ""$comments"" . PHP_EOL . PHP_EOL . "You can contact $name via email $email, or via phone $phone";
29
30
31if(!$mail->Send()) {
32 echo 'Message was not sent.';
33 echo 'Mailer error: ' . $mail->ErrorInfo;
34}else{
35 echo "<fieldset class='alert alert-success'>";
36 echo "<div id='message'>";
37 echo "<h1>Email Sent Successfully.</h1>";
38 echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
39 echo "</div>";
40 echo "</fieldset>";
41}
42
43
44
45?>
46
47$('#contactform').submit(function () {
48
49 var action = $(this).attr('action');
50
51 $("#message").slideUp(750, function () {
52 $('#message').hide();
53
54 $('#submit')
55 .after('<img src="images/loader.gif" class="loader" />')
56 .attr('disabled', 'disabled');
57
58 $.post(action, {
59 name: $('#name').val(),
60 email: $('#email').val(),
61 phone: $('#phone').val(),
62 subject: $('#subject').val(),
63 comments: $('#comments').val(),
64 //verify: $('#verify').val()
65 },
66 function (data) {
67 document.getElementById('message').innerHTML = data;
68 $('#message').slideDown('slow');
69 $('#contactform').fadeOut('slow', function () {
70 $(this).remove()
71 });
72 $('#submit').removeAttr('disabled');
73 if (data.match('success') != null) $('#contactform').slideUp('slow');
74
75 }
76 );
77
78 });
79
80 return false;
81
82});
83
84<form method="post" action="contacttest.php" name="contactform" id="contactform">
85 <div class="col-sm-12">
86
87 </div>
88 <div class="col-sm-12 p-top-40">
89 <fieldset>
90 <label for="name" accesskey="U">
91 <span class="required">*</span>Your Name</label>
92 <input class="form-control" name="name" type="text" id="name" size="30" value="" />
93 <br />
94 <label for="email" accesskey="E">
95 <span class="required">*</span>Email</label>
96 <input class="form-control" name="email" type="text" id="email" size="30" value="" />
97 <br />
98 <label for="phone" accesskey="P">
99 <span class="required">*</span>Phone</label>
100 <input class="form-control" name="phone" type="text" id="phone" size="30" value="" />
101 <br />
102 </fieldset>
103 </div>
104 <div class="col-sm-12 p-top-40">
105 <fieldset>
106 <label for="subject" accesskey="S">Subject</label>
107 <select class="form-control" name="subject" id="subject">
108 <option value="Support">Support</option>
109 <option value="a Sale">Sales</option>
110 <option value="a Bug fix">Report a bug</option>
111 </select>
112 <br />
113 <label for="comments" accesskey="C">
114 <span class="required">*</span>Your comments</label>
115 <textarea class="form-control margin-bottom-15" name="comments" cols="40" rows="5" id="comments"></textarea>
116 <button type="submit" class="btn btn-info btn-lg btn-fill" id="submit" value="Submit">Send Message</button>
117 </fieldset>
118 </div>
119 </form>