Absolutely! Here’s a comprehensive tutorial and troubleshooting guide for sending email from a GoDaddy VPS Server with cPanel + WHM. This includes PHP mail(), SMTP setup, logs, DNS settings, and common issues with solutions.
๐ง Sending Emails from GoDaddy VPS with cPanel + WHM
๐งฉ 1. How Email Sending Works on a cPanel VPS
| Component | Role |
|---|---|
| Exim | The default Mail Transfer Agent (MTA) |
| PHP | Uses Exim via /usr/sbin/sendmail for mail() |
| WHM | Manages global email delivery, logs, limits |
| cPanel | Manages email accounts and per-domain settings |
โ
2. Send Email Using PHPโs mail() Function
๐น Step 1: Create a PHP Script
<?php
$to = "your@email.com";
$subject = "Test Email from GoDaddy VPS";
$message = "This is a test email sent using PHP.";
$headers = "From: noreply@yourdomain.com";
if (mail($to, $subject, $message, $headers)) {
echo "โ
Email sent successfully.";
} else {
echo "โ Email sending failed.";
}
?>
Code language: HTML, XML (xml)
Save this as mailcheck.php inside your website’s public_html folder.
๐น Step 2: Access in Browser
Visit:
https://yourdomain.com/mailcheck.php
Code language: JavaScript (javascript)
You should see “โ Email sent successfully.”
๐ 3. Check Email Logs
SSH into the VPS:
sudo tail -f /var/log/exim_mainlog
Code language: JavaScript (javascript)
Other useful logs:
/var/log/exim_paniclogโ for fatal errors/var/log/exim_rejectlogโ for rejected messages
โ๏ธ 4. Configure SPF, DKIM, and DMARC (Important for Delivery)
โ๏ธ SPF & DKIM
- Go to WHM > Email > Email Deliverability
- Choose your domain
- Click “Repair” if SPF or DKIM are missing
- Copy the suggested DNS records to your GoDaddy DNS
โ๏ธ DMARC (Optional but Recommended)
Add this TXT record in DNS:
Name: _dmarc.yourdomain.com
Type: TXT
Value: v=DMARC1; p=none; rua=mailto:you@yourdomain.com
Code language: HTTP (http)
โ๏ธ 5. Send Email via SMTP (More Reliable)
Use this when sending emails from contact forms, apps, or Laravel/WordPress.
๐น Create an Email Account
In cPanel > Email Accounts, create:
- Email:
info@yourdomain.com - Password:
your_password
๐น Use PHPMailer (Example)
Install:
composer require phpmailer/phpmailer
Code language: JavaScript (javascript)
Code:
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'mail.yourdomain.com';
$mail->SMTPAuth = true;
$mail->Username = 'info@yourdomain.com';
$mail->Password = 'your_password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('info@yourdomain.com', 'Your Name');
$mail->addAddress('recipient@example.com');
$mail->Subject = 'SMTP Test Email';
$mail->Body = 'This email is sent using SMTP and PHPMailer.';
if ($mail->send()) {
echo 'โ
Mail sent!';
} else {
echo 'โ Mail failed: ' . $mail->ErrorInfo;
}
Code language: PHP (php)
๐ ๏ธ 6. Common Issues & Troubleshooting
| Problem | Solution |
|---|---|
mail() fails silently | Check /var/log/exim_mainlog |
| Mail lands in spam | Setup SPF/DKIM/DMARC correctly |
| Mail delivery delays | Check WHM > Mail Queue Manager |
| PHP can’t find sendmail | Ensure /usr/sbin/sendmail exists (default in WHM) |
| SMTP auth fails | Double-check credentials, port 587 with TLS |
| GoDaddy blocking ports | VPS is usually open, but shared hosting blocks SMTP ports |
๐ 7. Tips for Deliverability
- Use a real domain and valid “From” address (avoid
noreply@localhost) - Keep your IP clean (avoid spamming)
- Use
List-Unsubscribeheaders for bulk email - Monitor bounces and complaints
๐งช 8. Bonus: Webmail Testing
You can also send test emails from:
- Webmail: Access via
https://yourdomain.com/webmail - Login with the email you created in cPanel
๐งฐ Tools Recap
| Tool/Feature | Where |
|---|---|
| Email Accounts | cPanel |
| Mail Logs | /var/log/exim_mainlog |
| DNS Settings | WHM > Email Deliverability |
| Webmail Access | https://yourdomain.com/webmail |
| Mail Queue | WHM > Mail Queue Manager |
| SMTP Credentials | cPanel > Email Accounts |
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals