-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.php
47 lines (38 loc) · 1.33 KB
/
email.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
if(isset($_POST['button']))
{
//Load POST data from HTML form
$sender_name = $_POST["sender_name"]; //sender name
$reply_to_email = $_POST["sender_email"]; //sender email, it will be used in "reply-to" header
$subject = $_POST["subject"]; //subject for the email
$message = $_POST["message"]; //body of the email
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.spima.com;';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]', $sender_name);
$mail->addAddress($reply_to_email);
$mail->addAddress($reply_to_email, 'Name');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
$file_to_attach = 'upload/' . $_FILES['attachment']['name'];
move_uploaded_file($_FILES['attachment']['tmp_name'], $file_to_attach);
$mail->AddAttachment($file_to_attach);
$mail->send();
echo "Mail has been sent successfully!";
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>