Webmail及PHP mail函数发件显示成功但收件方未收到,求技术协助
Hey there, let's break down this problem step by step—since even your Roundcube webmail is showing sent messages but they're nowhere to be found in recipients' inboxes or spam folders, this leans more toward server-side mail configuration issues rather than your application code. But we'll cover both angles to be thorough.
Since Roundcube is having the same issue, your app code is probably not the culprit. The first thing to check is your server's mail logs—they'll tell you exactly what's happening to the messages after they leave your server.
For Linux servers, common log paths depend on your MTA (Mail Transfer Agent):
- Debian/Ubuntu:
/var/log/mail.log - CentOS/RHEL:
/var/log/maillog - cPanel/Exim setups:
/var/log/exim_mainlog
To check logs in real-time while sending a test email, run this command via SSH:
tail -f /var/log/mail.log
Look for errors like:
- Your server IP being blocked by a DNS-based blacklist (DNSBL) like Spamhaus
- Missing reverse DNS (PTR) record for your server IP
- Failed SPF/DKIM checks causing recipients' servers to discard the mail
- Host-level restrictions on outbound email (common for new servers to prevent spam)
These are the most common server-side issues that cause "sent but not received" mail:
- Reverse DNS (PTR Record): Reach out to your hosting provider and confirm your server IP has a PTR record pointing to your domain. Most reputable email servers reject mail from IPs without valid PTR records.
- SPF/DKIM/DMARC Records:
- SPF: Add an SPF TXT record to your domain's DNS that allows your server IP to send mail. Example:
v=spf1 ip4:123.123.123.123 -all - DKIM: Configure DKIM signing in your MTA (Exim, Postfix, etc.) and add the corresponding TXT record to your DNS. This validates that the mail actually came from your domain.
- DMARC: Add a DMARC TXT record to receive feedback on mail delivery. Example:
v=DMARC1; p=none; sp=none; rua=mailto:dmarc@yourdomain.com
- SPF: Add an SPF TXT record to your domain's DNS that allows your server IP to send mail. Example:
- IP Blacklist Check: Search for free IP blacklist tools to check if your server IP is listed on any spam databases. If it is, you'll need to appeal to the list operator or ask your host for a new IP.
While less likely, it's worth confirming your app's mail settings are correct:
- WordPress: If using WP Mail SMTP or similar plugins:
- Use a domain-specific email address (e.g.,
noreply@yourdomain.com)—avoid free services like Gmail/Yahoo, as they often block server-sent mail. - Confirm SMTP host (usually
mail.yourdomain.com), port (587 for TLS, 465 for SSL), and authentication credentials are correct.
- Use a domain-specific email address (e.g.,
- CodeIgniter: Verify your
application/config/email.phpsettings:
Avoid using external SMTP services unless you've configured OAuth or app passwords (Gmail, for example, no longer supports regular password authentication for server apps).$config['protocol'] = 'smtp'; $config['smtp_host'] = 'mail.yourdomain.com'; $config['smtp_port'] = 587; $config['smtp_user'] = 'noreply@yourdomain.com'; $config['smtp_pass'] = 'your_secure_password'; $config['smtp_crypto'] = 'tls'; $config['mailtype'] = 'html'; $config['charset'] = 'utf-8';
Eliminate the application layer entirely by sending a test email via SSH:
- Using
sendmail:echo "Test email body" | sendmail -v recipient@example.com - Using
mail:mail -s "Test Subject" recipient@example.com < /dev/null
Check the output for immediate errors, then cross-reference with your mail logs.
If you've gone through all the above and still can't find the issue, it's time to contact your host's support team. Provide them with excerpts from your mail logs—they'll have access to server-level restrictions or network issues you can't see (like blocked ports, internal blacklists, or missing mail server licenses).
内容的提问来源于stack exchange,提问作者Robin Rai

