I have been working toward filling gaps in my coding knowledge, and I hope to tackle PHP soon, but in the meantime I am stumbling through the creation of a simple PHP based contact form in order to put the finishing touches on a website.
I've taken the code from a super basic (and license free) tutorial and tailored it to my needs. Everything appears to work, except that I do not receive the test email, sent from the form.
The tutorial had me create two .php files. One for the page on the site containing the form, and another for it to communicate with in order to send the email. The first file is actually XHTML (with a touch of JavaScript, which I'm new to), but the tutorial told me to use the .php extension, so I have.
Here is the current code for both files (sans the XHTML):
<?php
// Contact subject
$subject ="$subject";
// Details
$message="$message";
// Mail of sender
$from="$email";
// From
$header="from: $name <$from>";
// Enter your email address
$to ='my@private.email';
$send=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send){
echo "<b>Thank you</b>.<br />We will get back to you very soon.";
}
else {
echo "<b>ERROR</b>: Please be sure that you complete all fields and try again.";
}
?>
Again, the remaining issue is simply that the test email doesn't arrive in my inbox. I successfully reach the page with the quote: "Thank you. We will get back to you very soon."
Seems like this should be SUCH a simple task. Any help will be so appreciated. : )
Gracious thanks!
-Tye
Last edited by TyeNewton; 07-02-2010 at 07:07 AM..
Reason: I realized that I mislabeled my own code.
The host is GoDaddy. Considering their high profile, I'd expect they'd cover all the bases, but I guess I don't know... I know there was mention of php support during sign up, but you're just talking about the mail() function, I see.
Do you know where I should look for this information on GoDaddy's site? This is only the third time I've ever purchased hosting, and everything still seems very cluttered and convoluted to me.
Looks pretty generalized so it must cover all GoDaddy accounts, right??
--
I suppose I should still try your idea, though, Benny.
Are you suggesting I swap your code with my ContactSend.php file, then use the form to test it?? (Sorry about my lack of php knowledge.)
I suppose I should still try your idea, though, Benny.
Are you suggesting I swap your code with my ContactSend.php file, then use the form to test it?? (Sorry about my lack of php knowledge.)
No he isn't. Just create a php file with that code (i.e. just go to notepad and rename to .php) and upload to you web server. Then run the script by going to yourwebserver/nameofphpfile.php. The code will output a message in your browser saying whether you are able to use the mail function.
Does GoDaddy force the use of their gdform.php form mailer? Or is that just a dummies version of form mailing? I know there have been several questions on that here. A forum search might turn up something.
Good news:
I tried Benny's test for mail() function support and it turned up positive.
Interesting news:
I also tried Aerospace's error-checking suggestion and received the following report...
"Notice: Undefined variable: subject in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 5
Notice: Undefined variable: message in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 7
Notice: Undefined variable: email in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 10
Notice: Undefined variable: name in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 12"
Looking back at my code, the lines it refers to are $subject ="$subject";, $message="$message";, $from="$email";, and $header="from: $name <$from>";. Basically every single variable received from the form.
Does this mean that it is in fact NOT receiving information from the form? If so, I must be reaching the "Thank you." message in error, correct?
On the other hand, if it IS receiving information from the form, then I can understand why it wouldn't like my "subject" and "message" variables, as those appear to refer to themselves, but I'm at a total loss as to why it doesn't like my "from" and "header" variables. : /
This is actually a website for my own father's business, so in the meantime, I am going to attempt to test out miseim's hypothesis by changing the "to" address to my father's email (the one associated with the GoDaddy account).
I forgot to also add that I don't fully grasp what tomws is asking about. I wouldn't be surprised if what I'm using is a "dummies" version, however. ; )
Okay, so nothing was received by my father's email, either. However, I'm wondering now if mlseim (oops! I misspelled your username before) meant that the address has to be associated with the domain? My father still prefers to use his ISP email address, so we didn't bother purchasing email support with the domain.
I'll poke around at GoDaddy's documentation for an answer, in any case.
(Is it weird that I'm referring to everyone in the third person? I'm do more search than posting on forums, so I apologize if my posting habits appear rude. Also, should I be quoting people more?)
Re: undefined variable. You're not "catching" the values from the form. The assignments you're using worked in PHP4, but not in PHP5 (unless the server operator has opened up a little security hole). Use this instead:
PHP Code:
$myVar = $_POST['myVar']; // or $myVar = $_GET['myVar'];
<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
// Contact subject
$subject ="$subject";
// Details
$message="$message";
// Mail of sender
$from="$email";
// From
$header="from: $name <$from>";
// Enter your email address
$to ='my@private.add';
$send=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send){
echo "<b>Thank you</b>.<br />We will get back to you very soon.";
}
else {
echo "<b>ERROR</b>: Please be sure that you complete all fields and try again.";
}
?>
Into this:
Code:
<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
// Contact subject
$subject = $_Get[ '$subject' ];
// Details
$message = $_Get[ '$message' ];
// Mail of sender
$from = $_Get[ '$email' ];
// From
$header = $_Get[ 'from: $name <$from>' ];
// Enter your email address
$to = $_Post[ 'my@private.add' ];
$send=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send){
echo "<b>Thank you</b>.<br />We will get back to you very soon.";
}
else {
echo "<b>ERROR</b>: Please be sure that you complete all fields and try again.";
}
?>
I'm not sure if I needed the $_POST for the "to" address, or if this is even correct at all.(?) Seems like there must be something more I need to do to the $send and $header variables.
Wuh-oh,
This time all of the same variables plus line 15 (the "to" address) turned up undefined.
I guess I didn't translate that properly, haha.
I apologize again for tackling this with so little prior php knowledge. Again, I intend to properly learn javascript and php after I finish with the first installment of this and another website.