-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendemail.php
51 lines (40 loc) · 1.56 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
45
46
47
48
49
50
51
<?php
header('Content-Type: application/json');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
//echo json_encode("Başarılı");
if($_POST){
$name = $_POST['firstname'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'host.com';
$mail->SMTPAuth = true;
$mail->SMTPAutoTLS = false;
$mail->Username = '[email protected]';
$mail->Password = '12345';
$mail->SMTPSecure = false;
$mail->Port = 587;
$mail->CharSet = 'UTF-8';
//Recipients
$mail->setFrom('[email protected]', 'Admin');
$mail->addAddress('[email protected]', $name); // Add a recipient
$mail->addReplyTo($email,$name);
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Example sitesi üzerinden gönderilen yeni iletiniz var.';
$mail->Body = '<b>Gönderen Ad Soyad: </b>'.$name.'</br></br> <b>Konu: </b>'.$subject.'</br></br> <b>Mesaj: </b><br>'.$message;
$mail->AltBody = '';
$mail->send();
echo json_encode(['status' => 'success','msg' => 'Başarıyla mesajınız gönderilmiştir.']);
} catch (Exception $e) {
echo json_encode(['status' => 'error','msg' => 'Mesajınız gönderilememiştir.']);
}
}