-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.php
59 lines (46 loc) · 1.56 KB
/
mail.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
52
53
54
55
56
57
58
59
<?php
require __DIR__ . '/vendor/autoload.php';
require_once(__DIR__ . '/config.php');
require_once(__DIR__ . '/phpmailer/PHPMailer.php');
require_once(__DIR__ . '/phpmailer/SMTP.php');
require_once(__DIR__ . '/phpmailer/Exception.php');
// mail
$body = ""; // initialize the variable before the loop
$c = true;
$title = "Send mail"; // theme mail
// body
foreach ($_POST as $key => $value) {
if ($value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject") {
$body .= "
" . (($c = !$c) ? '<tr>' : '<tr style="background-color: #f8f8f8;">') . "
<td style='padding: 10px; border: 1px solid #e9e9e9;'><b>$key</b></td>
<td style='padding: 10px; border: 1px solid #e9e9e9 ;'>$value</td>
</tr>
";
}
}
$body = "<table style='width: 100%;'>$body</table>";
// setting PHPMailer
$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true;
// setting my mail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
// config.php
$mail->Username = SMTP_USERNAME; // Change the value to your email address (e.g. "[email protected]")
$mail->Password = SMTP_PASSWORD; // Replace SMTP_PASSWORD with your actual password for apps
$mail->setFrom(EMAIL_FROM); // Sender's name
// The person who receives the email.
$mail->addAddress(EMAIL_TO);
// SEND MAIL
$mail->isHTML(true);
$mail->Subject = $title;
$mail->Body = $body;
$mail->send();
} catch (Exception $e) {
$status = "Message was not sent. Error: {$mail->ErrorInfo}";
}