问题
Here are my configuration files.
sendmail.ini
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.
smtp_server=(Correct SMTP Server)
; smtp port (normally 25)
smtp_port=25
php.ini
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = (Correct SMTP Server)
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = (user@(server.com)) <- correct name
PHP code
<?php
$from_name = "testing";
$from_email = "myemail@something.com";
$headers = "From: $from_name <$from_email>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$body = "Hi,\nThis is a test mail from $from_name <$from_email>.";
$subject = "Test mail from test";
$to = "myemail@something.com";
if (mail($to, $subject, $body, $headers)) {
echo "success!";
} else {
echo "fail…";
}
?>
When i ran the code, it indeed say email sent but when I checked the email, there is nothing to receive... please help! thank you i will provide as many relevant information as possible to solve this issue.
回答1:
If you're testing this from home or a small office then your ISP is likely to be blocking out-bound traffic on port 25. You're PHP will not fail but your message will be blocked. You'll need to connect to an external SMTP server on another port such as 465 or 587. Consult your ISP's website for the details on what they allow.
回答2:
If you look closely you will see you're missing a concatenation on your second $header variable, therefor, you're not sending the "From:" header which is likely causing the mail to be rejected.
来源:https://stackoverflow.com/questions/10117170/email-sent-but-not-received-on-inbox-php-localhost-xampp-web-server