Trying to combine two sets of someone else's code

If you replace the variables with the actual data, your first example (correct code) is:
if( dy337y==dy337y&&1) Note: you are AND’ing a string with a number. !empty is either 0 or 1
for the incorrect code:
if( gh8rwp==NULL&&1) Note: an empty variable is either tested as NULL or 0, both will not work here!

So, this has turned out a bit tricky and confusing. Also, the second display showed another error. You only UNSET the security value when the results are positive, you leave it in place if the tests fail. That is why your second display showed the gh8rwp. this was due to the fact that the compare fails because of the ANDing of the string with the isset’s 1. Hope that made sense. So, here is one way to correct these issues.
For these two lines:

if( isset($_POST[‘submit’]) && isset($_SESSION[‘security_code’]) ) {
if( $_SESSION[‘security_code’] == $_POST[‘security_code’] && !empty($_SESSION[‘security_code’] ) ) {

Change them to this:
[php]
if( isset($_POST[‘submit’]) && isset($_SESSION[‘security_code’]) ) {
if( $_SESSION[‘security_code’] == $_POST[‘security_code’] ) {
[/php]
What this does is only process all the code if it is SUBMITTED and has a SESSION security_code set and then removes the extra compare. The other way would be to add ()'s around the == section, but, this way is better. Note that in the first compare, you are ANDing (&&) bits, 0 and 1 in whatever combination they happen to be. ANDing 0’s and 1’s are always correct. No mixed data-types such as strings and 1’s as in the old versions. Then, the second compare is a straight forward one.

As far as the old security code being left active, you can UNSET it after the message that they have given an incorrect security code at the end. Also, you may want to UNSET it after the an email error where it says email-error-message-not-sent. In that way, they have to retype the code if an error occurs.

Let us know… And, sorry that I didn’t catch that tricky compare issue sooner! Hope it works!

Hi results for correct code
Array ( [fieldnm_1] => Paul [fieldnm_2] => Fereday [fieldnm_3] => Romart [fieldnm_4] => [fieldnm_5] => [fieldnm_6] => [fieldnm_7] => LL11 4SR [fieldnm_8] => 0123456789 [fieldnm_9] => [email protected] [fieldnm_10] => Testing [security_code] => 4dh5ps [Submit] => Submit )

Array ( [security_code] => 4dh5ps )

Debug listing complete

Hi results for incorrect code

Array ( [fieldnm_1] => Paul [fieldnm_2] => Fereday [fieldnm_3] => Romart [fieldnm_4] => [fieldnm_5] => [fieldnm_6] => [fieldnm_7] => LL11 4SR [fieldnm_8] => 0123456789 [fieldnm_9] => [email protected] [fieldnm_10] => Testing [security_code] => [Submit] => Submit )

Array ( [security_code] => gf5vw3 )

Debug listing complete
tested with out the debug code same blank pages

[php]<?php
session_start();
// Temporary debug displays…
print_r($_POST);
echo “

”;
print_r($_SESSION);
echo “

”;
die(“Debug listing complete”);
// End of temporary debug code…

if( isset($_POST[‘submit’]) && isset($_SESSION[‘security_code’]) ) {
if( $_SESSION[‘security_code’] == $_POST[‘security_code’] ) {
$fromemail=“No-Reply [email protected]”; // change here if you want
$toemail="[email protected]"; // change here if you want
$sub=“Online Feedback”; // change here if you want
$success_page_name=“success.html”;
$fieldnm_1=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_1’])));
$fieldnm_2=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_2’])));
$fieldnm_3=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_3’])));
$fieldnm_4=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_4’])));
$fieldnm_5=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_5’])));
$fieldnm_6=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_6’])));
$fieldnm_7=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_7’])));
$fieldnm_8=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_8’])));
$fieldnm_9=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_9’])));
$fieldnm_10=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_10’])));
$contentmsg="
$sub

First Name *: $fieldnm_1
Last name *: $fieldnm_2
House name or number *: $fieldnm_3
Address: $fieldnm_4
$fieldnm_5
Address: $fieldnm_6
Post code *: $fieldnm_7
Phone Number *: $fieldnm_8
Email *: $fieldnm_9
Comments : $fieldnm_10
"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: $fromemail"; // Security checked out and email set up, now try to send it... if(mail($toemail,$sub,$contentmsg,$headers)) { unset($_SESSION['security_code']); header("Location:$success_page_name"); } else { // Insert your code for showing an email error message here echo 'Email error, message was not sent!'; } } else { // Security check failed, say so... echo "Sorry, you have provided an invalid security code!"; } // END of security check code... } // END of isset(post)... ?> [/php]

Does the email send to you? And, do you have something in the success page?

Hi
No emails and yes their is a success page
Success Page Html

[code]

Success

Thank you We will be in touch soon

[/code]

Paul, I am so very sorry! I did not catch this earlier! CAPS, my pal, CAPS!!!

You have “submit” as what you are testing for, but, in the debug listing it is “Submit” !

Small difference, but, PHP is “caps” sensitive! “submit” is not the same value as “Submit” ! ! !

Yes, I think that is the problem. A simple capital “S”…

NOTE, none of your other variables are cap’d. Just the Submit button, so I overlooked it.

Try that, changing the PHP code to check for “Submit” and let us know! Hope that does it!

Hi
You’ve cracked the success page and the security code message but no email was sent

Also no email error message

The lasted file code
[php]<?php
session_start();

if( isset($_POST[‘submit’]) && isset($_SESSION[‘security_code’]) ) {
if( $_SESSION[‘security_code’] == $_POST[‘security_code’] ) {
$fromemail=“No-Reply [email protected]”; // change here if you want
$toemail="[email protected]"; // change here if you want
$sub=“Online Feedback”; // change here if you want
$success_page_name=“success.html”;
$fieldnm_1=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_1’])));
$fieldnm_2=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_2’])));
$fieldnm_3=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_3’])));
$fieldnm_4=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_4’])));
$fieldnm_5=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_5’])));
$fieldnm_6=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_6’])));
$fieldnm_7=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_7’])));
$fieldnm_8=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_8’])));
$fieldnm_9=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_9’])));
$fieldnm_10=stripslashes( str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_10’])));
$contentmsg="
$sub

First Name *: $fieldnm_1
Last name *: $fieldnm_2
House name or number *: $fieldnm_3
Address: $fieldnm_4
$fieldnm_5
Address: $fieldnm_6
Post code *: $fieldnm_7
Phone Number *: $fieldnm_8
Email *: $fieldnm_9
Comments : $fieldnm_10
"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: $fromemail"; // Security checked out and email set up, now try to send it... if(mail($toemail,$sub,$contentmsg,$headers)) { unset($_SESSION['security_code']); header("Location:$success_page_name"); } else { // Insert your code for showing an email error message here echo 'Email error, message was not sent!'; } } else { // Security check failed, say so... echo "Sorry, you have provided an invalid security code!"; } // END of security check code... } // END of isset(post)... ?>[/php]

Wow, I still can’t believe that I missed that CAP issue! LOL…

So, now all is working but, the email is not being sent? Well, we should first debug the email line of code to see if all the data is correct! Just before the email line:
( if(mail($toemail,$sub,$contentmsg,$headers)) { )
Add some debug lines to see what is really being sent out. Something like this would work:
[php]
echo "to-email: " . $toemail . “

”;
echo "subject: " . $sub . “

”;
echo "content: " . $contentmsg . “

”;
die ("headers: " . $headers . “

End of email debug!”);

if(mail($toemail,$sub,$contentmsg,$headers)) {
[/php]
This should give you four lines of data that would be sent to the emal system. Look at each and make sure they are correct. My guess is that one of these is not valid. Let us know what you have…
Note: the ‘die’ at the end and the message is there so that you can see where the end of the headers actually are, sometimes they are a bit messed up… Let us know…

Hi
That’s the form that’s you get when you get an email

to-email: [email protected]

subject: Online Feedback

content:
Online Feedback

First Name *: Paul
Last name *: Fereday
House name or number *: Romart
Address:

Address:
Post code *: LL11 4SR
Phone Number *: 0123456789
Email *: [email protected]
Comments : Testing

headers: MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 From: No-Reply

End of email debug!

Sorry cant test any more the wife’s threating blue murder if I don’t take her out.

I’m an confused. I thought you said it was NOT sending out the emails?

So, it does send you an email?

Your data looks correct as far as I can see!

LOL, okay, let us know when you can! Always make the wife happy first!!! Later…

Hi No emails are coming into my inbox or any where else, just double checked no emails

Paul, a few post’s ago, I gave you the code to debug your email. It basically shows what is being sent to the mail routine. You should test that and see what data is incorrect. If the TO address is wrong, you will not get the email. Or, if the headers are incorrect, they will not process the email. Try that and see if something jumps out at you. If not show us the results…

Every thing is as it should be

toemail: [email protected]

subject: Online Feedback

content:
Online Feedback

First Name *: Paul
Last name *: Fereday
House name or number *: Romart
Address:
Address:
Address:
Post code *: LL11 4SR
Phone Number *: 0123456789
Email *: [email protected]
Comments : Testing

headers: MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 From: No-Reply

End of email debug!

This is a live one not the test one I copied the source from my email package

[code]Return-path: [email protected]
Envelope-to: [email protected]
Delivery-date: Tue, 30 Jul 2013 16:31:27 +0100
Received: from kensing1 by zurich.footholds.net with local (Exim 4.80.1)
(envelope-from [email protected])
id 1V4BtX-00056H-Pw
for [email protected]; Tue, 30 Jul 2013 16:31:27 +0100
To: [email protected]
Subject: Online Feedback
X-PHP-Script: www.kensington-sashwindows.co.uk/_sendmail.php for 109.150.41.208
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
From: No-Reply [email protected]
Message-Id: [email protected]
Date: Tue, 30 Jul 2013 16:31:27 +0100


Online Feedback

First Name *: Paul
Last name *: Fereday
House name or number *: Romart
Address:
Address:
Address:
Post code *: LL11 4SR
Phone Number *: 0123456789
Email *: [email protected]
Comments : Testing
[/code]

Code for the live one
[php]<?php ob_start();
$fromemail=“No-Reply [email protected]”; // change here if you want
$toemail="[email protected]"; // change here if you want
$sub=“Online Feedback”; // change here if you want
$success_page_name=“success.html”;
////// do not change in following
if($_SERVER[‘REQUEST_METHOD’]==“POST”)
{
$fieldnm_1=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_1’]));
$fieldnm_2=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_2’]));
$fieldnm_3=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_3’]));
$fieldnm_4=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_4’]));
$fieldnm_5=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_5’]));
$fieldnm_6=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_6’]));
$fieldnm_7=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_7’]));
$fieldnm_8=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_8’]));
$fieldnm_9=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_9’]));
$fieldnm_10=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_10’]));

$contentmsg=stripslashes("
$sub

First Name *: $fieldnm_1
Last name *: $fieldnm_2
House name or number *: $fieldnm_3
Address: $fieldnm_4
Address: $fieldnm_5
Address: $fieldnm_6
Post code *: $fieldnm_7
Phone Number *: $fieldnm_8
Email *: $fieldnm_9
Comments : $fieldnm_10
");

////
$headers = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";

$from=$fromemail;

$headers .= "From: “.$from.”
";

@mail($toemail,$sub,$contentmsg,$headers);

header(“Location:$success_page_name”);

}
?>[/php]

Many things can cause an email to not be sent. What server are you using? Is it a Windows server or a Linux system with Apache? Here is one note that might be the cause:

If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.

For that, try changing the \r\n to just \n and retest.

Also, the header that you display:
" headers: MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 From: No-Reply "
Does NOT have the line feed between the MIME-type and the FROM. So, I am guessing it is due to something in that section.

NEVER MIND! From some reason, you changed the code. Here is the HEADER’s section with the line-feed back in place. That is your problem!
[php]
////
$headers = “MIME-Version: 1.0\r\n”;
$headers .= “Content-type: text/html; charset=iso-8859-1\r\n”;

$from=$fromemail;

$headers .= “From: “.$from.”\r\n”;

@mail($toemail,$sub,$contentmsg,$headers);

header(“Location:$success_page_name”);
[/php]
In sending an email, you can NOT just add an HTML return as you have. You MUST use the \r\n (escaped versions) to send the email with. Try that. Good luck!

Success coming through now thanks loads your amazing

Step by step, my pal! Sorry it took so long. It is hard to see code in someone else’s system… LOL

Glad we solved it. I will mark this one SOLVED! If you have another section that needs help, please start a new post!

Good luck with your site!

Sponsor our Newsletter | Privacy Policy | Terms of Service