This guide explains how to configure email functionality for student registration notifications.
The system uses PHP's built-in mail() function for sending emails. For production environments, you may need additional configuration.
- Configured mail server on your hosting environment
- For local development (XAMPP), you need to configure PHP to send emails
Open C:\xampp\php\php.ini and modify the following lines:
[mail function]
SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = lspuscc.soccs@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"Open C:\xampp\sendmail\sendmail.ini and configure:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=lspuscc.soccs@gmail.com
auth_password=your_app_password_here
force_sender=lspuscc.soccs@gmail.com- Go to Google Account Settings
- Enable 2-Step Verification
- Go to App Passwords
- Generate a new app password for "Mail"
- Use this password in
sendmail.ini
After configuration, restart Apache in XAMPP Control Panel.
cd C:\xampp\htdocs\soccs-financial-management
composer require phpmailer/phpmailerReplace includes/email_config.php with:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
class EmailService {
private $fromEmail = 'lspuscc.soccs@gmail.com';
private $fromName = 'SOCCS Admin';
private $smtpHost = 'smtp.gmail.com';
private $smtpPort = 587;
private $smtpUsername = 'lspuscc.soccs@gmail.com';
private $smtpPassword = 'your_app_password';
public function sendEmail($to, $subject, $htmlMessage) {
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = $this->smtpHost;
$mail->SMTPAuth = true;
$mail->Username = $this->smtpUsername;
$mail->Password = $this->smtpPassword;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = $this->smtpPort;
// Recipients
$mail->setFrom($this->fromEmail, $this->fromName);
$mail->addAddress($to);
// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $htmlMessage;
$mail->send();
return true;
} catch (Exception $e) {
error_log("Email Error: {$mail->ErrorInfo}");
return false;
}
}
// ... rest of the methods
}
?>Create a test file test_email.php:
<?php
require_once 'includes/email_config.php';
$emailService = new EmailService();
$result = $emailService->sendRegistrationConfirmation(
'your_test_email@example.com',
'Test User',
'TEST001'
);
if ($result) {
echo "Email sent successfully!";
} else {
echo "Failed to send email. Check error logs.";
}
?>- XAMPP:
C:\xampp\sendmail\error.log - PHP errors:
C:\xampp\php\logs\php_error_log
Solution:
- Verify SMTP credentials
- Check firewall settings
- Enable "Less secure app access" or use App Password for Gmail
Solution:
- Add SPF and DKIM records to your domain
- Use a verified sender email address
- Avoid spam trigger words in email content
Solution:
- Check if port 587 or 465 is blocked by firewall
- Try alternative SMTP ports
- Verify internet connection
- Most hosting providers have pre-configured PHP mail()
- Use hosting provider's SMTP settings
- Consider using services like SendGrid, Mailgun, or Amazon SES
For security, store credentials in .env file:
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=lspuscc.soccs@gmail.com
SMTP_PASSWORD=your_app_password
SMTP_FROM_EMAIL=lspuscc.soccs@gmail.com
SMTP_FROM_NAME=SOCCS AdminUpdate email_config.php to read from environment:
private $smtpPassword = $_ENV['SMTP_PASSWORD'] ?? '';The system sends two types of emails:
- Registration Confirmation - Sent immediately after registration
- Approval Notification - Sent when admin approves the registration
Both templates are in includes/email_config.php and can be customized.
- ✅ Never commit SMTP passwords to Git
- ✅ Use App Passwords instead of account passwords
- ✅ Enable 2FA on email accounts
- ✅ Use environment variables for sensitive data
- ✅ Regularly rotate SMTP credentials
- ✅ Monitor email sending logs
- ✅ Implement rate limiting to prevent spam
For issues or questions:
- Check PHP error logs
- Review sendmail debug logs
- Contact system administrator
- Email: lspuscc.soccs@gmail.com