I had a call yesterday off someone I've done some PHP work for. He had set up a site with an eCard on it and just found an eCard script to deal with the mailing. Quite fine you'd assume. He had it working on his server fine. Then he moved it to the client's server and it stopped working. Over the phone I made a few obvious suggestions, does the mail() function work? Try a simple test of a hardcoded straightforward mail:
- Email Code
- <?php mail("firstname.lastname@example.org", "This is a quick test", "testing 1 2 3", "From: email@example.com"); ?>
I also suggested the from address must be a valid email address on the server, as the server may have security in place to prevent it being sent from a non server address. Also, after this morning, I've discovered that even a valid email address could have DNS issues with some servers, so if one doesn't work, try another too!
Anyhow, he came back to me and said the mail function worked fine, so I FTP'd in and took a look at the code. At first glance it seemed fine enough. Pretty shabby PHP but nothing giving a reason for it not to work. I took a look at the web page again and then noticed it wasn't picking up the to and from email addresses. A second, more serious look made me notice the script assumed that Registered Globals were on, a major no no as a lot of servers have the default installation of PHP which switches them off, or servers deliberately ensure they're off for security. So I ran through, updated the variables to use the $_POST array and voila, it worked.
So for future reference, if you want to write PHP code, write it properly from the beginning! Don't assume options such as registered globals are available to you. Using $_GET, $_POST, $_FILE etc will work fine regardless of whether registered globals are on or off, and it's far more secure to use this method.
Also whilst talking about portable PHP…
Use proper opening tags ie. <?php and not just <?.
At least if you cover these portability issues, then when things don't work as planned you can rule them out as issues and turn to other options.