-
Notifications
You must be signed in to change notification settings - Fork 0
/
email-sender.php
48 lines (39 loc) · 1.11 KB
/
email-sender.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
<?php
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'];
$password = $_POST['password'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$attachment = $_FILES['attachment'];
$currentEmail = $_POST['current_email'];
$mail = new PHPMailer(true);
try {
// Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = $email;
$mail->Password = $password;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Recipients
$mail->setFrom($email);
$mail->addAddress($currentEmail);
// Attachments
if ($attachment['error'] === UPLOAD_ERR_OK) {
$mail->addAttachment($attachment['tmp_name'], $attachment['name']);
}
// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
echo 'Email sent successfully.';
} catch (Exception $e) {
echo 'Error sending email: ' . $mail->ErrorInfo;
}
}