Jump to content

PHP Mail Form probs


loydster

Recommended Posts

I am getting post backs from this form. Can anyone give me a clue what I'm doing wrong? Also any tip on how to make this spam proof? Thanks.

 

<?php

ini_set("sendmail_from", "loyd@loydster.com");

if(isset($_POST['submit'])) {

$to = "loydster@comline.com";

$subject = "Inquiry or Comment";

$name_field = $_POST['name'];

$email_field = $_POST['email'];

$message = $_POST['message'];

$option = $_POST['radio'];

$dropdown = $_POST['drop_down'];

 

foreach($_POST['check'] as $value) {

$check_msg .= "Checked: $value\n";

}

 

$body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";

 

echo "Thank you for contacting $to!";

mail($to, $subject, $body);

 

} else {

echo "Error on email posting.";

}

?>

if(isset($_POST['submit'])) {

 

ON SUBMIT I GET THIS ERROR MESSAGE:

Notice: Undefined variable: check_msg in d:\Customers\user1220675\www\mailer.php on line 13

Thank you for contacting loydster@comline.com!if(isset($_POST['submit'])) {19

Link to comment
Share on other sites

how bout you try to initialize $check_msg to whatever value you want before going inside foreach(). i think its because you are using .= right away without initializing (a guess, ahehe).

 

anti spam? try captcha or use the string: plus or minus in your website.

Link to comment
Share on other sites

That's not an error, its a notice, which is a non-fatal message which just gives you information about an irregularity in your script. In this case, the first time the script goes through the foreach loop, it is asked to append "Checked: $value\n"; to the variable $check_msg, which doesn't exist, hence the undefined error. To fix it, just add

 

$check_msg = "";

 

before the foreach loop. Also, you are getting the text about if(isset..... because you have it written outside the closing PHP tag.

 

Dan

 

ahh... beaten by bluejay. :)

Link to comment
Share on other sites

Thank you Dan and Bluejay. Is there anything I can add to the code to refresh the HTML after the PHP mail is submitted? I get the "Thank you for contacting me" screen, but if I hit the back button to go back to my site, the form is still populated. I'm assuming that i need to beef up the HTML to refresh the page when the "Submit" button is clicked? Thanks again for the help.

Link to comment
Share on other sites

Excuse my density, but is this the scenario? I add the metatag to my HTML on the "Contact" page. The user enters his info and submits the PHP contact form. The reply page "Thank you..." loads. If the user goes back the page is still populated with the data he/she entered, right? If I set the page to refresh itself automatically, don't I stand a good chance of losing posts from end users? Is there any way to set the PHP "thank you" response page to redirect to the "contact" page? This would refresh the page automatically as well and not generate uneeded or unwanted refresh of the page. Thank you for your patience.

Link to comment
Share on other sites

Is there any way to set the PHP "thank you" response page to redirect to the "contact" page? This would refresh the page automatically as well and not generate uneeded or unwanted refresh of the page.

 

Put the meta tag at the thank you page then that meta tag to redirect to contact page after several seconds and you may also include a link to contact if the user want to redirect right away and dont want to wait. back is always present... if you want to remove that... then check its browsing history and forbid the client. a little Google will do. :)

Link to comment
Share on other sites

I am unable to find good references to this. My code thus far:

 

<?php

ini_set("sendmail_from", "loyd@loydster.com");

$to = "loydster@comline.com";

$subject = "Inquiry or Comment";

$name_field = $_POST['name'];

$email_field = $_POST['email'];

$message = $_POST['message'];

$option = $_POST['radio'];

$dropdown = $_POST['drop_down'];

$check_msg = "";

 

foreach($_POST['check'] as $value) {

$check_msg .= "Checked: $value\n";

}

if(isset($_POST['submit'])) {

$body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";

 

echo "Thank you for contacting loydster.com";

mail($to, $subject, $body);

 

 

} else {

echo "Message Error.";

 

When I try adding the <meta http-equiv="refresh" content="delay_in_seconds; url=specify_url_here" /> tag to the PHP to initiate my thankyou.html page, the PHP of course displays only text "thankyou.htm". I know I am close here but what am I doing wrong? I want the PHP to display the thankyou.html upon successful posting of the message. This would automatically refresh the page as the user would have to click a menu page from there. Thank you.

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.