This topic is locked
[SOLVED]

  Code for a send email - with twist.

9/26/2011 8:10:49 PM
PHPRunner General questions
ladykathleen author

I am working with PHPrunner 6.0
What I am wanting to do is:
User adds a record(table A). I have a field (field 1) in that record that does a drop down lookup from another table(Table B ).
In the table that was looked up there might be an email attached to the record.
So I would like to use the email from table B and email that person if the user selected that lookup result in Table A.
Any Help would be apprecaited.
Kathleen

C
cgphp 9/27/2011

In the "Before record added" event, check if for the field_1 an email address exists in the Table_B using a custom query. If so, send an email message to that address.

$rs = CustomQuery("SELECT email_field_name FROM TABLE_2 WHERE id_field_name=".$values['field_1_name']." AND email_field_name IS NOT NULL LIMIT 1");

$record = db_fetch_array($rs);

if($record)

{

$from="admin@test.com";

$msg="Hello there\nBest regards";

$subject="Sample subject";

runner_mail(array('to' => $record['email_field_name'], 'subject' => $subject, 'body' => $msg, 'from'=>$from));

}
ladykathleen author 9/30/2011



In the "Before record added" event, check if for the field_1 an email address exists in the Table_B using a custom query. If so, send an email message to that address.

$rs = CustomQuery("SELECT email_field_name FROM TABLE_2 WHERE id_field_name=".$values['field_1_name']." AND email_field_name IS NOT NULL LIMIT 1");

$record = db_fetch_array($rs);

if($record)

{

$from="admin@test.com";

$msg="Hello there\nBest regards";

$subject="Sample subject";

runner_mail(array('to' => $record['email_field_name'], 'subject' => $subject, 'body' => $msg, 'from'=>$from));

}



Thank you Cristian I will try that and let you know how it goes.
Kathleen

ladykathleen author 9/30/2011

It seems that php does not like the CustomQuery
I am getting a error 256

It does not seem to like this section WHERE id_field_name=".$values['field_1_name']." AND email IS NOT NULL LIMIT 1
I used the right field names when running it. the value in that field should be test but shows as blank and the error says the syntax is wrong.
It says the section of the query is WHERE Title= AND email IS NOT NULL LIMIT 1

C
cgphp 9/30/2011

I thought that the field values was numeric. Insert quotes around the field value. Here it is the fixed code:

$rs = CustomQuery("SELECT email_field_name FROM TABLE_2 WHERE id_field_name='".$values['field_1_name']."' AND email_field_name IS NOT NULL LIMIT 1");

$record = db_fetch_array($rs);

if($record)

{

$from="admin@test.com";

$msg="Hello there\nBest regards";

$subject="Sample subject";

runner_mail(array('to' => $record['email_field_name'], 'subject' => $subject, 'body' => $msg, 'from'=>$from));

}
ladykathleen author 9/30/2011



I thought that the field values was numeric. Insert quotes around the field value. Here it is the fixed code:

$rs = CustomQuery("SELECT email_field_name FROM TABLE_2 WHERE id_field_name='".$values['field_1_name']."' AND email_field_name IS NOT NULL LIMIT 1");

$record = db_fetch_array($rs);

if($record)

{

$from="admin@test.com";

$msg="Hello there\nBest regards";

$subject="Sample subject";

runner_mail(array('to' => $record['email_field_name'], 'subject' => $subject, 'body' => $msg, 'from'=>$from));

}



This worked as far as getting past the error Thanks!!
Waiting for the email to arrive now to see if that part worked.. no email as of yet.
is there a way to check if it sent an email out?

C
cgphp 9/30/2011

Be sure the SMTP directive in the php.ini file is correctly set.

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = your_smtp_address
ladykathleen author 9/30/2011



Be sure the SMTP directive in the php.ini file is correctly set.

[mail function]

; For Win32 only.

; http://php.net/smtp

SMTP = your_smtp_address



That is mostly likely my problem on that.. Thanks again..

ladykathleen author 9/30/2011



That is mostly likely my problem on that.. Thanks again..


Cristian
This is what is in my Php.ini for that section now.
[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25
; For Win32 only.

;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").

sendmail_path = /usr/sbin/sendmail -t -i
; Force the addition of the specified parameters to be passed as extra parameters

; to the sendmail binary. These parameters will always replace the value of

; the 5th parameter to mail(), even in safe mode.

;mail.force_extra_parameters =
we are not on a windows server, does that make a difference?

C
cgphp 10/1/2011

On other platforms, PHP should use the locally available sendmail or sendmail drop-in just fine.

ladykathleen author 10/4/2011



On other platforms, PHP should use the locally available sendmail or sendmail drop-in just fine.


So far I have not been able to get the system to send me an email.
I will try searching the forums tomorrow to see if there is anything that will help.

Sergey Kornilov admin 10/5/2011

As a first step - make sure simple email works. Create a test PHP file name test.php and run it in browser

<?php
mail('youremailaddresshere', 'Subject', 'Message');

?>



If this doesn't work something is not right with mail setup and you need to talk to your web server admin in order to resolve this,

ladykathleen author 10/5/2011



As a first step - make sure simple email works. Create a test PHP file name test.php and run it in browser

<?php
mail('youremailaddresshere', 'Subject', 'Message');

?>



If this doesn't work something is not right with mail setup and you need to talk to your web server admin in order to resolve this,


Ok I got the email from the simple so that part worked. so maybe my coding was off, checking it again now.
adding my code in case you see something I missed.
$rs = CustomQuery("SELECT email FROM jobsjob2 WHERE Title='".$values['JobApplyingfor']."' AND email IS NOT NULL LIMIT 1");

$record = db_fetch_array($rs);

if($record)

{

$from="webmaster@reliablestaffing.com";

$msg=$values['JobApplyingfor']." ".$values['FirstName']." ".$values['MiddleName']." ".$values['LastName'];

$subject="Job Match";

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

}

C
cgphp 10/5/2011

Check if the query result is empty. Try to echo the record before the if statement:

echo $record['email'];
ladykathleen author 10/5/2011



Check if the query result is empty. Try to echo the record before the if statement:

echo $record['email'];



it did not display anything anywhere, so if it is not because my page design that means my query must be empty.

ladykathleen author 10/5/2011

OK I think I figured out what is wrong..
Under jobjob2 field Title = Test

But under the JobsApp the JobApplyingfor is a #
So I just need to make it match ID not Title in jobjobs2 instead of the field title..
For some reason I knew it had to be something small and silly.
Thanks Testing it now..

ladykathleen author 10/5/2011

Ok I changed this $rs = CustomQuery("SELECT email FROM jobsjob2 WHERE Title='".$values['JobApplyingfor']."' AND email IS NOT NULL LIMIT 1");
to this $rs = CustomQuery("SELECT email FROM jobsjob2 WHERE ID='".$values['JobApplyingfor']."' AND email IS NOT NULL LIMIT 1");
and now at least the ID and JobApplyingfor both = the same value. no email still
so as they are numbers instead of text. I changed ".$values['JobApplyingfor']."
and that gives me a php error. (same as orginally.
so I am stuck again for the moment...
Got to go do something then I will be back at it in a bit.

ladykathleen author 10/5/2011

OK I worked out this so far
The email part does work.
it is the calling of variables did not work.
I tell it that ID = 123 it finds the record and emails the result.
but seems the whole problem was JobAppyingFor and JobApplyingfor (the F) (I could just kick myself right now)

So with that fixed I can press on with the rest of my program.
Thank you so much for the help as now I am getting closer to my goal.
"Don't ya just hate it when it is a silly thing like that above?"