This topic is locked
[SOLVED]

 send email based on specific field value

9/21/2012 10:39:39 AM
PHPRunner General questions
S
scoobysteve author

Hi I would like to send one of 2 emails base one of my filed values, the field has a drop down box so no chance of spelling mistakes.

I have tried the following code which I have used before to check a numeric value so not sure if this is right. I am using this in the "after record added" on the Add page. The results are that the same option is used each time the first one. Even if I chenge the location to another town.
Thanks in advance Steve
if(!isset($data['Location']) || trim($data['Location'])==='Albufeira')

{

$email="emailoption1.com";

$from="email.com";

$msg="We would like to register a new client with your company ".$values["FirstName"]." ".$values["LastName"]." , Please can you confirm the details and registration of this client, thank you Lorna Watts";

$subject="Registration of new client from Algarve Team Properties Lda no 1";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}

else

{

$email="emailoption2.com";

$from="email.com";

$msg="We would like to register the following client with your company ".$values["FirstName"]." ".$values["LastName"]." , Please can you confirm the details and registration of this client, thank you Lorna Watts";

$subject="Registration of new client from Algarve Team Properties Lda no 2";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}

C
cgphp 9/21/2012

Dump the $data['Location'] variable before the if statement:

var_dump($data['Location']);

exit();
if(!isset($data['Location']) || trim($data['Location'])==='Albufeira')

{

$email="emailoption1.com";

$from="email.com";

$msg="We would like to register a new client with your company ".$values["FirstName"]." ".$values["LastName"]." , Please can you confirm the details and registration of this client, thank you Lorna Watts";

$subject="Registration of new client from Algarve Team Properties Lda no 1";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}

else

{

$email="emailoption2.com";

$from="email.com";

$msg="We would like to register the following client with your company ".$values["FirstName"]." ".$values["LastName"]." , Please can you confirm the details and registration of this client, thank you Lorna Watts";

$subject="Registration of new client from Algarve Team Properties Lda no 2";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}


What is the output?

S
scoobysteve author 9/21/2012



Dump the $data['Location'] variable before the if statement:

var_dump($data['Location']);

exit();
if(!isset($data['Location']) || trim($data['Location'])==='Albufeira')

{

$email="emailoption1.com";

$from="email.com";

$msg="We would like to register a new client with your company ".$values["FirstName"]." ".$values["LastName"]." , Please can you confirm the details and registration of this client, thank you Lorna Watts";

$subject="Registration of new client from Algarve Team Properties Lda no 1";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}

else

{

$email="emailoption2.com";

$from="email.com";

$msg="We would like to register the following client with your company ".$values["FirstName"]." ".$values["LastName"]." , Please can you confirm the details and registration of this client, thank you Lorna Watts";

$subject="Registration of new client from Algarve Team Properties Lda no 2";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}


What is the output?


The output in both cases is NULL

C
cgphp 9/21/2012

Check if you have initiliazed the $data['Location'] variable correctly.

S
scoobysteve author 9/21/2012



Check if you have initiliazed the $data['Location'] variable correctly.


Sorry I dont know how to do this, the location field is working and is populating the mysql database when a new entry has been completed by the selection of the drop down box of towns.
Do I need to use the $_SESSION["UserID"] at all in the event so it knows what record it is ??
Thanks

Steve

C
cgphp 9/21/2012

Use $values['Location'] not $data['Location']

S
scoobysteve author 9/21/2012

Cristian
the output on the dump was
string(9) "Albufeira"
I have also tried
if ($values ['Location']= "Albufeira")
still the same result if I save one record with Albufeira as the location and another record if its not Albufeira.
Thanks

Steve

C
cgphp 9/21/2012

Make sure Location is the real name of the field: Location is different from location (case sensitive).

When you do a comparison, use == not =

S
scoobysteve author 9/23/2012

Ok I think the double == thing might have been it thanks
Steve