Welcome to the blog of Mr.G
composer require phpmailer/phpmailer
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php'; // Load PHPMailer via Composer
function sendAuctionEmail($recipientEmail, $recipientName, $subject, $message) {
$mail = new PHPMailer(true);
try {
// SMTP settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // SMTP server (use your provider if not Gmail)
//$mail->Host = 'myappz.com';
//$mail->Hostname = 'mail.myappz.com';
$mail->SMTPAuth = true;
$mail->Username = 'your-email@gmail.com'; // Your email address
$mail->Password = 'your-email-password'; // Use an "App Password" if using Gmail
//$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
//$mail->Port = 587;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
// $mail->SMTPDebug = 2; // Use 2 for verbose output
// $mail->Debugoutput = function ($str, $level) {
// file_put_contents('phpmailer_debug.log', "[$level] $str\n", FILE_APPEND);
// };
// Email headers
$mail->setFrom('your-email@gmail.com', 'Auction Alerts'); // Sender email & name
$mail->addAddress($recipientEmail, $recipientName); // Recipient email & name
$mail->Subject = $subject;
$mail->Body = $message;
$mail->isHTML(true); // Allows HTML content (optional)
// Send email
$mail->send();
return "📧 Email sent successfully to $recipientEmail";
} catch (Exception $e) {
return "❌ Email failed: " . $mail->ErrorInfo;
}
}
require 'sendmail.php';
// Example: Send an email when 15 minutes remain
$recipientEmail = "user@example.com";
$recipientName = "John Doe";
$subject = "Auction Alert: 15 Minutes Left!";
$message = "Hello $recipientName, this is a reminder that your auction is ending in 15 minutes.";
echo sendAuctionEmail($recipientEmail, $recipientName, $subject, $message);
Gmail (and other email providers) require proper email authentication to prevent spam and to verify that emails are coming from legitimate sources. This typically involves SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail).
Here’s how to set up SPF and DKIM to make your email deliverable to Gmail and other providers:
SPF is used to verify the sending mail server is authorized to send emails on behalf of your domain.
Log in to your DNS provider (where you manage your domain settings).
Add a TXT record for SPF:
@ (or your domain name)TXTv=spf1 a mx ip4:12.123.123.12 ~allv=spf1 → Specifies it's an SPF record.a → Accepts mail from the IP address of the A record.mx → Accepts mail from any server listed in the MX records for the domain.ip4:12.123.123.12 → Allows mail from the IP 12.123.123.12 (your server IP).~all → Soft fail (emails from unauthorized servers are marked but not rejected).Save and apply the record. It may take a few minutes for DNS propagation.
DKIM adds a digital signature to the email, allowing the receiving mail server (like Gmail) to verify that the email was sent by an authorized server and that it wasn’t tampered with during transit.
Generate DKIM Keys using OpenSSL or a service like EasyDKIM or Plesk (if you're using it).
Publish the DKIM public key in your DNS as a TXT record:
default._domainkeyTXTv=DKIM1; k=rsa; p=MIGfMA0GCSq...<your public key>...Q1cQConfigure Postfix (or your mail server) to sign outgoing emails with your private DKIM key.
DMARC (Domain-based Message Authentication, Reporting & Conformance) is used to ensure your emails are being authenticated properly with SPF and DKIM. It's optional, but highly recommended to increase your domain's email security.
Create a TXT record in your DNS for DMARC:
_dmarcTXTv=DMARC1; p=none; rua=mailto:dmarc-reports@mydomain.comExplanation:
v=DMARC1 → Specifies it’s a DMARC record.p=none → Policy (set to "none" to only monitor without rejecting).rua=mailto:dmarc-reports@mydomain.com → Where to send reports about DMARC failures.Once you have set up SPF, DKIM, and optionally DMARC, you can test your email authentication using tools like:
Once all of this is in place, emails from smtp.mydomain.com will pass Gmail’s SPF and DKIM checks, making them more likely to be delivered to the inbox.
Lem - Warren Buffett walked into a University of Florida classroom in 1998 ... [2098423133938356224] (1)
Sam Stoffel - Jack Dorsey's simple rule for success in business [2089319019065057280]
Peter-Steinberger-What-Happens-When-4.7-_1786407922546
Monitor_server_action____
Disk_and_RAID_testing_commandsWebDev New York London AI NORWAY DIY Ideas Life Family News Clothing Invest Sports Health