In brief: When a website sends registration email with PHP’s built-in mail() function, the hosting server may rewrite the sender identity. The message can arrive, but it may appear to come from a hosting account or server hostname instead of the website’s brand.
1. Understand the problem before changing code
The registration system was already working: users could register and receive welcome and notification emails. The issue was sender identity, not registration itself. The old sender appeared as a hosting-domain address while the desired identity was a branded mailbox on the website’s domain.
From address:
noreply@example.com
We kept the registration logic intact and focused on the mail transport layer. A useful troubleshooting principle is to change the smallest component that solves the problem.
2. Confirm the mailbox and SMTP settings in cPanel
Create or confirm the branded mailbox in cPanel Email Accounts. Then use the account’s Connect Devices or mail-client settings to confirm the SMTP values supplied by the hosting provider.
| Setting | Example |
|---|---|
| SMTP host | mail.example.com |
| Port | 465 |
| Encryption | SSL/TLS (implicit TLS) |
| Authentication | Enabled |
| Username | noreply@example.com |
| From name | Your Brand |
Host providers may use different values. Always validate SMTP settings against the provider’s current documentation.
3. Install PHPMailer without SSH or Composer
On shared hosting where Terminal or Composer is unavailable, PHPMailer can be uploaded manually. Download it from the official PHPMailer repository.
public_html.src directory.Exception.php, PHPMailer.php, and SMTP.php exist.public_html whenever possible.4. Store SMTP credentials outside the public website
Create a private PHP configuration file in the private folder. The following structure illustrates where the settings belong:
Replace the placeholder only on the server. Never publish a mailbox password in a repository, screenshot, chat, or browser-facing file.
5. Test SMTP in isolation before touching registration
Do not change the registration flow immediately. First create a temporary test script or endpoint to isolate PHP execution, include paths, mailbox authentication, and message delivery.
A blank page is not a diagnosis. Check PHP execution, file paths, permissions, and hosting error logs one at a time.
This excerpt assumes PHPMailer is already loaded and that the private configuration path has been resolved securely.
6. Verify the delivered sender—not just “send succeeded”
Open the actual delivered email and inspect its From address and message headers. A PHP success response proves only that the script reached a code branch; it does not prove that the recipient received the intended identity.
Your Brand <
noreply@example.com>
7. Change the transport layer and preserve email content
After isolated SMTP testing succeeds, update only the shared mail-sending function in the existing application. Preserve subjects, HTML templates, personalization, recipient lists, and registration behavior.
Run end-to-end checks for registration, login, welcome email, notification recipients, and error logging. Email failure should not silently block account creation or expose credentials.
8. Remove temporary diagnostic files
Delete temporary public test and PHP diagnostic files after testing. Do not delete the real mailer, private configuration, authentication logic, or PHPMailer library.
smtp-test.phpphp-check.php
9. Troubleshooting checklist
- Blank test page: inspect PHP errors and hosting logs; avoid blind repeated edits.
- “Failed opening required”: verify exact paths, filenames, capitalization, and PHP include permissions.
- SMTP authentication error: confirm mailbox username, password, host, port, and encryption.
- Email accepted but not received: check spam folders, delivery logs, DNS records, and message headers.
- Wrong sender persists: confirm the SMTP account is authorized to send as the From address.
- Registration succeeds but email fails: log the failure privately and keep account creation behavior under review.
What we learned
- Separate sender identity problems from registration bugs.
- Use authenticated SMTP instead of relying on shared-host
mail()behavior. - Install libraries outside the public directory where possible.
- Keep credentials private and out of client-side code.
- Debug one layer at a time and verify the received email.
- Back up files and preserve working application logic.
- Delete diagnostic endpoints immediately after testing.
Directory paths, SMTP hosts, PHP versions, and provider rules vary. Validate settings with the hosting provider before moving anything to production.