3

I am stuck and cannot figure out for the life of me why this is not working. It was working before. I have changed the emails addresses below for security reasons.

$to = "email@domainname.com";
$subject = "Submission";
$body = "Test Body";
$header = "From: email@domainname.com";                
if (mail($to, $subject, $body, $header)) {
    echo "message was successfully sent.";
    echo "$to $subject <br/> $body <br/> $header";
} else {
    echo "There was a Problem.";
};
jprofitt
  • 10,874
  • 4
  • 36
  • 46
n_starnes
  • 376
  • 1
  • 6
  • 20
  • 3
    Define "not working". Does it show "There was a Problem" or does it say it sent but doesn't? – jprofitt May 17 '12 at 16:58
  • There are no errors and says it sent even in the logs. I have checked by mail server and there have been no emails received by the mail server or any caught in spam. – n_starnes May 17 '12 at 16:59
  • remove the header and see what happens: mail($to, $subject, $body) – Adam May 17 '12 at 17:00
  • It was working before what? What changed? – j08691 May 17 '12 at 17:01
  • I removed the header and still says message sent. Nothing changed that is what is weird. I am the only person with access to anything and it just stopped working. – n_starnes May 17 '12 at 17:02
  • 1
    Have you Checked check if mailserver is running: `nmap -p 25 |grep open` ? – Zuul May 17 '12 at 17:05
  • just checked and mailserver is indeed running. – n_starnes May 17 '12 at 17:10
  • Check this page, it covers the same issue! [Stackoverflow :: PHP mail() doesn't work](http://stackoverflow.com/q/6403746/352449) – Zuul May 17 '12 at 17:18
  • Have you tried sending mail to multiple, unrelated addresses/domains? – j08691 May 17 '12 at 17:19
  • @Zuul I am checking that page now and j08691 I have tried my work, personal(live.com), a gmail and other email accounts does not change anything. – n_starnes May 17 '12 at 17:28
  • @Zuul i have gone over everything in that post and everything is correct or i just tried it. – n_starnes May 17 '12 at 17:38
  • Do you know for sure that the destination account is receiving mails? – Zuul May 17 '12 at 18:02
  • Yes, I have been actively receiving emails all day from my customers. – n_starnes May 17 '12 at 18:22
  • if you're trying this on *nix server, what if you run this: "tcpdump -nvvXS port 25" from root? Do you see somewhere in packet contents 250.Accepted or something like that? What do you see in packet contents before QUIT command – Alexey May 17 '12 at 18:38
  • I looked at our mail server and changed the spam filter settings just to see what would happen. Low and behold everything is working fine now. The odd thing is it wasn't showing that the email had even been received. But regardless problem solved. Thanks everyone for their help it is appreciated. – n_starnes May 17 '12 at 20:44

2 Answers2

0

First: You have to be sure that your ambiente is configured properly. Your script will not show error messages either.

Hint: User PHPMailer. (http://phpmailer.worxware.com/) This class show spefic messages, and them you can fix whats is wrong.

Important: If you are unsure where is the error, you will be frustrated in trying and trying without directions. There can be many causes for the e-mail will not be sent.

Use PHPMail and find out where is the bug, after that you can ask here again, the advantage is that you have a description of the error.

I had a similar problem and PHPMail helped me a lot!

So, try it and tell us the error.

0

I looked at our mail server and changed the spam filter settings just to see what would happen. Low and behold everything is working fine now. The odd thing is it wasn't showing that the email had even been received. But regardless problem solved. Thanks everyone for their help it is appreciated.

n_starnes
  • 376
  • 1
  • 6
  • 20