-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmtp_example.php
More file actions
36 lines (31 loc) · 1.44 KB
/
Copy pathsmtp_example.php
File metadata and controls
36 lines (31 loc) · 1.44 KB
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
<?php
// Example: Sending email using PHPMailer with SMTP
// 1. Download PHPMailer: https://github.com/PHPMailer/PHPMailer
// Place the PHPMailer src/ folder in your project (e.g., includes/PHPMailer/)
// 2. Use the following code to send an email:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'includes/PHPMailer/Exception.php';
require 'includes/PHPMailer/PHPMailer.php';
require 'includes/PHPMailer/SMTP.php';
require 'includes/env.php';
$mail = new PHPMailer(true);
try {
// SMTP server configuration
$mail->isSMTP();
$mail->Host = env('SMTP_HOST', 'smtp.gmail.com'); // SMTP server (e.g., smtp.gmail.com)
$mail->SMTPAuth = true;
$mail->Username = env('SMTP_USERNAME', ''); // Your SMTP username
$mail->Password = env('SMTP_PASSWORD', ''); // Your SMTP password or app password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Encryption (tls or ssl)
$mail->Port = (int) env('SMTP_PORT', 587); // SMTP port (587 for TLS, 465 for SSL)
// Email settings
$mail->setFrom(env('SMTP_FROM', env('SMTP_USERNAME', '')), env('SMTP_FROM_NAME', 'CAI Admin'));
$mail->addAddress('caiofficial03@gmail.com', 'CAI Admin');
$mail->Subject = 'Test SMTP Email';
$mail->Body = 'This is a test email sent using SMTP and PHPMailer.';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}