-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendemail.php
44 lines (36 loc) · 1.51 KB
/
sendemail.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
require_once 'phpmailer/Exception.php';
require_once 'phpmailer/PHPMailer.php';
require_once 'phpmailer/SMTP.php';
$mail = new PHPMailer(true);
$alert = '';
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$reason = $_POST['reason'];
$message = $_POST['message'];
try{
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // Gmail address which you want to use as SMTP server
$mail->Password = 'ilovesugu'; // Gmail address Password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = '587';
$mail->setFrom('[email protected]'); // Gmail address which you used as SMTP server
$mail->addAddress('[email protected]'); // Email address where you want to receive emails (you can use any of your gmail address including the gmail address which you used as SMTP server)
$mail->isHTML(true);
$mail->Subject = 'Message Received (Contact Page)';
$mail->Body = "<h3>Name : $name <br>Email: $email <br> Reason: $reason <br>Message : $message</h3>";
$mail->send();
$alert = '<div class="alert-success">
<span>Message Sent! Thank you for contacting us.</span>
</div>';
} catch (Exception $e){
$alert = '<div class="alert-error">
<span>'.$e->getMessage().'</span>
</div>';
}
}
?>