tags:

views:

54

answers:

3

Hello everybody, I have the following code which works on some servers and does not work on others:

$Name = "myname"; //senders name
            $email_sender = "[email protected]"; //senders e-mail adress
            $recipient = $email; //recipient
            $mail_body = "The text for the mail..."; //mail body
            $subject = "Subject for reviever"; //subject
            $header = "From: ". $Name . " <" . $email_sender . ">\r\n"; 
                        $status = mail($recipient, $subject, $mail_body, $header); 
            print('ENVOI '. $status);

The $status variable is true but I don't see any email.

A: 

This may or may not be related but you have a pretty simple header, I would replace your header variable with something like what's below and see if that changes anything for you.

$headers = 'From: ' .$email_sender. "\r\n" .
    'Reply-To: ' .$email_sender. "\r\n" .
    'X-Mailer: PHP/' . phpversion();
Sam152
The server is APACHE SERVER, i check the sendmail_from function there was no value then i put [email protected] but i still don't see the email in my inbox.
Mamadou
Umm, I don't think the right domain to use is localhost.com.
Sam152
Hi guys, I can't solv my mail server problem ! I heard a bout ' PHPMAILER' . this may help me tu use the mailing php function ! Can someone tell me more about this , MERCI
Mamadou
A: 

Make sure you smtp setting are correct on the servers in question.

Syed
+1  A: 

$status being true doesn't mean the mail was RECEIVED by your recipient. It just means the mail function successfully delivered the mail to the LOCAL delivery agent. After that it's out of PHP's hands.

The process looks something like this:

  1. PHP script calls mail()
  2. mail() delivers message to the local mail server (sendmail, postfix, exim, etc..)
  3. mail(), having successfully completed 'delivery' of the email, returns TRUE
  4. local mail server connect's to recipient's mail server, delivers mail
  5. recipient's mail server does whatever it has to to get the email into the recipient's inbox.

Since mail() is returning true, that means that at least your sending code is correct enough to not cause things to blow up at that stage. That leaves delivery problems between your and the recipients' mail servers:

a) Perhaps the recipient is using greylisting (in which case the mail SHOULD eventually show up). Maybe your server gives up before the greylist timeout period expires, so the retry attempt(s) is never made.

b) your mail server is blacklisted. Your server, and/or some other potential spam source is in the same netblock have been added to one or more anti-spam RBL lists the recipient subscribes to.

c) Perhaps the remote server is very prickly about header correctness and your server's a bit too relaxed about one or more headers.

At least these problems SHOULD be visible in your own mail server's maillog (generally /var/log/maillog on most Unix-ish systems). Try sending a test mail while watching the log to see how the message procedes through the system. Also check the server's outgoing mail queue (mailq command, usually). Maybe the missing messages are stuck in there.

And then there's the bigger problems:

d) the remote mail server is accepting the message, but silently tossing it because it's flagged as spam or as infected. This you can't detect from your own mail logs, as this is done purely on the recipient end. All you'll see is the "250 OK" success message.

For this you'll need the recipient's help in diagnosing the problem.

Marc B
Thank you for this response really clear. Am going to check the maillog, check the parth of the mail server in the path in php.ini.. i will be back to tell what is happening !
Mamadou