mail() $_POST question

Hi first time here really hope someone can help!
im trying to fire off an automated email then the following conditions have been met frames_in = yes and collected = no I have tried the following code but am a newbe and cant for the life of me figure it out

[php]if (isset($_POST[‘frame_in’]) == “yes”) && (isset($_POST[‘collected1’]) == “no”) {
mail($mailTo,$subject,$message,$headers);
}[/php]

Looks a little bit like you’re trying to do too much in one statement.

If I’m correct ‘isset()’ returns a boolean ( true/false ) not ( ‘yes’/‘no’ ). Your test probably works but it correctly decises true != ‘yes’.

If you want to do that all in one line it should look something like this:
[php]
if ( isset( $_POST[‘frame_in’] ) &&
isset( $_POST[‘collected’] ) && // You mention ‘collected’ and the code reads ‘collected1’
$_POST[‘frame_in’] == ‘yes’ &&
$_POST[‘collected’] == ‘no’ )
{ mail( $mailto, $subject, $message, $headers );
}
[/php]

( an if() evaluates to boolean, so ‘isset() == true’ is a bit double )
Hope this helps! :smiley:

Thanks for your help but for some reason it still doesn’t fire off the email??

Perhaps the parts of the mail function are not set up correctly.
If you take out the if clause and just send the email does it go out?
You may be sending bad mail headers.

Perhaps you should show us how you create these mail variables…

Here is my full mail script:

<?php $mailTo = $row_Recordset3['email']; $subject = 'Your Oder Status Update!!'; $cName = $row_Recordset3['c_name']; $jobRef = $row_Recordset1['customer_ref']; $ourRef = $row_Recordset1['our_ref']; $framesIn = $row_Recordset1['frame_in']; $glassin = $row_Recordset1['glass_in']; $panelin = $row_Recordset1['panel_in']; $roofin = $row_Recordset1['roof_in']; $jobTotal = $row_Recordset1['amount1']; $headers = 'From: [email protected]' . "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $message = "$cName your job Ref: $jobRef status is has now changed.

Details:

Our Ref: $ourRef
Your Ref: $jobRef
Job Total: £ $jobTotal

Status

Frames In:$framesIn
Glass In:$glassin
Panel In:$panelin
Roof In:$roofin

"; if($_POST['frame_in'] == "yes" && $_POST['collected1'] == "no") { mail($mailTo,$subject,$message,$headers); } ?>

Please note ‘collected1’ is correct also the email fires with the following:

if ($_POST[‘frame_in’] == “yes”) {
mail($mailTo,$subject,$message,$headers);
}

I need to add the additional check Collected1 == “no” so that the email doesnt fire off when the job is finally collected changed to collected.
Thanks for helping :slight_smile:

Thanks for the additional info…
Looks like the logic is bad for the if clause…
This:

if($_POST[‘frame_in’] == “yes” && $_POST[‘collected1’] == “no”) {

breaks down to IF x==(y&&z)==q… Not what you want… Try this instead:

if(($_POST[‘frame_in’] == “yes”) && ($_POST[‘collected1’] == “no”)) {

I bet that does it! Good luck… Off to bed, will check in a few hours from now…

Unfortunately if didn’t work :o

Well, the only other thing I can see is you are using a special character for your Euro.
Try echoing your values and see if they are set up correctly.

echo $mailTo . “
”;
echo $subject . “
”;
echo $message . “
”;
echo $headers . “
”;

And make sure each are formatted correctly. Either way let us know…

Very strange, it all echo’s out fine:

[email protected]
Your Oder Status Update!!
Ken Sutton your job Ref: Jill status is has now changed.
Details:

Our Ref: 21368
Your Ref: Jill
Job Total: £

Status

Frames In: yes
Glass In: yes
Panel In: no
Roof In: no

From: [email protected] MIME-Version: 1.0 Content-type: text/html; charset=utf-8

Hmmm??? Puzzling… If you take out the IF and just email it does it email.
I did some studying and your old IF should work. Try without it and see if it sends…

Hi sorry for the delay in coming back ive been away,

I have tried removing the IF and the page now doesn’t load at all, im thinking there is quite a bit of php (3 reccordsets) going on in the page and wondering if there is a conflict somewhere and its a little above my knowledge it figure out lol

Thanks for your help all the same :slight_smile:

The number of datasets should not be an issue. One note, you are testing this on a live site, right? I mean, you can not send emails on a local test system without using SMTP.

You can set a couple of flags to show ALL errors to see if there is some hidden PHP error that is not showing up. You do that by adding these to your code:

error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);

If PHP has an error, they are not always all shown… With these two lines, it may show something…

Sponsor our Newsletter | Privacy Policy | Terms of Service