Forum Moderators: coopster
If you'd like to sticky me the code, I'll be glad to see if anything looks wrong with it to my eye, but I do suspect the server config.
What does that mean?
It means it should work. That path indicates that SendMail is loaded and setup correctly.
Write a test page:
<?php
$send = mail('youremail@address.com','test','I'm testing the mail.');
echo $send;
?>
If $send is one, then the mail has been sent. You should also get the mail if you put in your email address.
But I talked to my hosting service, and he's going to talk to some people at his work and see if they can figure it out...(he doesn't know much about php.)
If not, then we're out of options (unless someone comes up with something we've overlooked) and your host will need to resolve it. Sorry.
First, it looks to me like you are trying to have the same file be both the submission form and the form processing agent. Is this right? If not I really don't understand your source at all.
Assuming that you do mean to have a self-processing form, I would reccomend a structure along the lines of this:
<?php
if (we_got_POST_data)
{
process_form();
}
else
{
print_form()
}function print_form()
{
?> Standard HTML form here <?php
}function process_form()
{
if (Post_data_makes_sense)
{
compose message;
if (mail(all those args you know))
{
print confirmation;
}
else
{
print error message;
}
}
else
{
Tell user what went wrong;
}
}
?>
Obviously, I've left out a lot of details, and this is pseudocode that won't run, but I think you get the idea. The function calls aren't strictly necessary, but I think they are a good organizational tool and the cost is pretty minimal on such a simple script.
I think you'll find it's easier to keep track of what your script is doing if you don't try to decide which mode to be in every few lines, but rather determine that once, and then do all the work for a particular state in one place.
That path indicates that SendMail is loaded and setup correctly
Umm... it could perfectly well be a correct path. It might not be - it wouldn't work on some of my machines.
I'm havinging the devil's own time getting the code she sent me to run on my own server, where register_globals is turned off. However, I see nothing wrong with her syntax in the mail() command.
but then why isn't my code working?
Here's what my hosting service told me:
>>>>>>>>>>>>>>>>>
Well, PHP can be used for a "mailback" form. We don't have either pop or imap compiled into php but simple sending does work.
Also, "Globals" are not enabled. Apparently, there have been numerous security risks with having them on.
>>>>>>>>>>>>>>>>>>
What exactly does this mean, and how do I fix my code?
What's the version number of PHP you are using? it changes the best way to do it.
Basically, what they are saying is that the "normal" configuration for PHP is to add any form variables to the global scope before you start processing - that's why you are used to just being able to use variable from the form. If register_globals is turned off, though, you have to explicitly fetch them. It is a security issue, depending on how your scripts are written.
You can deal with it pretty easily by starting the PHP code off with:
$formvar = $_POST['formvar'];
or
global $HTTP_POST_VARS;
$formvar = $HTTP_POST_VARS['formvar'];
The first line is the better way, if you have a version of PHP new enough to understand it. (4.1.0 and above)
More complete info can be found at [php.net...]
function deliver_message(){
foreach ($_POST as $field => $contents) {
$message_body .= "$field}:\n{$contents}\n\n-=-=-=-=-=-=-=-=-=-\n\n";
}$sent = mail('oneofmynames@oneofmydomains.com',
"[oneofmydomains.com contact form] {$_POST['subject']}",
$message_body);return $sent;
}
Works with or without register globals.
18: Two ways to get the value from <input name="formvar" ...> into $formvar. Since you have PHP 4.2.0, use the first. It's better.
20: An example piece of code that uses the same approach as the first one in message 18, more or less, but it just grabs every value from the form rather than getting each one by name.
Make sense?