mail() help again, can not receive the email sent.

W

wilson

Guest
Hi,
I started to learn php yesterday.
And wrote my first php file.
It calls the mail() to send an email.

code:

.......
ini_set(SMTP,"localhost");
ini_set(smtp_port,8081);
mail( "[email protected]", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.google.com" );
.......

After I testing the php, it showed me the email was sent successfully( without any error information and opened the www.google.com). But I can not find the email sent in the [email protected].
I have downloaded a software called Free SMTP Server to run on my machine. It also showed me my php program used the port 8081 to send the email.

appreciate any help......
 
Port 8081 is an odd one for SMTP. You might want to confirm that. Typical is 25. You could change your code to:

PHP:
$returnValue = mail( "[email protected]", "Feedback Form Results", $message, "From: $email" );
if($returnValue === true) echo 'Success!';
else echo 'Sending failed';

That will tell you if mail() talked to your SMTP server or not. If it is, perhaps your mail is being sent but blocked by a spam filter? You're not using complete headers, which is sometimes seen as a sign that a message is spam. Here's a snippet of code from a mail script I've written:

PHP:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: php\r\n";
$headers .= "From: " . $from . "\r\n";
$headers .= "Reply-To: " . $from . "\r\n";
if(strlen(trim($cc)) > 0) {
	$headers .= "CC: " . $cc . "\r\n";
}
if(strlen(trim($bcc)) > 0) {
	$headers .= "BCC: " . $bcc . "\r\n";
}
mail($to, $subject, $body, $headers);

(Check out http://www.skypanther.com/spmailer.php for the full code.)

Tim
 
Back
Top