-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmail.php
40 lines (32 loc) · 1.08 KB
/
sendmail.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once'vendor/autoload.php';
function sendEmail($recipientEmail, $subject, $body, $path , $name) {
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'fkvawdrjzgnklheb';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]', $name);
$mail->addAddress($recipientEmail);
$mail->addReplyTo('[email protected]', 'No-Reply');
$mail->AddStringAttachment($path, 'invoice.pdf');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = strip_tags($body); // Plain text version for non-HTML clients
$mail->send();
return true; // Indicate successful sending
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
return false; // Indicate failure
}
}
?>