This topic is locked

Email ID

6/18/2009 5:01:02 AM
PHPRunner General questions
G
Greeham author

Hello,
I currently have a system set up, weher by Engineers can submit spares requests (through the Add Record page) and the resuktant information is emailed to the Administrator (Before Record added event) and it works great.
But, I cannot seem to have the ID value attached to the email:-
So for example, tabel lay out (For purposes of demo):-
id

engineer

partno

partname

status
I can get all the infomration into the email using BeforeRecordd added event (Email) but the ID won't ever show in it or even if I try and have the value shown after the record added.
Any ideas how I can solve this issue? The id field is my primary key and Auto Inc. (Don't know if that matters). Do i need to maybe have another request ID field? If so, how do I get this info into the email?
Thanks,
Graham

lewisgr 6/18/2009

What does the code look like. You probably would never get the ID using the Before Record added event because the record hasn't been added to the database to create the ID yet.

Hello,

I currently have a system set up, weher by Engineers can submit spares requests (through the Add Record page) and the resuktant information is emailed to the Administrator (Before Record added event) and it works great.
But, I cannot seem to have the ID value attached to the email:-
So for example, tabel lay out (For purposes of demo):-
id

engineer

partno

partname

status
I can get all the infomration into the email using BeforeRecordd added event (Email) but the ID won't ever show in it or even if I try and have the value shown after the record added.
Any ideas how I can solve this issue? The id field is my primary key and Auto Inc. (Don't know if that matters). Do i need to maybe have another request ID field? If so, how do I get this info into the email?
Thanks,
Graham

G
Greeham author 6/18/2009

Hi,
I did think of that so tried using the email after record added but that just returns an sql error.
Perhaps I will try again...
Thanks,
Graham

J
Jane 6/18/2009

Graham,
use After record added event and following code for this purpose:

$id = mysql_insert_id();

G
Greeham author 6/18/2009

Graham,

use After record added event and following code for this purpose:


Hi Jane,
Thanks, add this in the email do you mean?
Thanks,
Graham

G
Greeham author 6/18/2009

If i use the email function in after record added I get a php error telling me that the undefined variable: message is unknown but if I use the same in Before record added it emails correctly?
Thanks,

L
laonian 6/18/2009

The id field is my primary key and Auto Inc. (Don't know if that matters). Do i need to maybe have another request ID field? If so, how do I get this info into the email?


I guess this is where the problem came from. Since I did not see your exact coding, I assume that you have not used the $keys variable for the id value (for primary key field). If that is true, could you try '".$keys["id"]."' for it and see whether it works?

G
Greeham author 6/19/2009

This didn't work. Herre is my code:-
$email="blah@blah.com,".$values["engineermail"]."";

$subject="Spares Request";

$date_value = $values["date"];

$date_value = date("d-m-Y",strtotime($date_value));
$headers= "MIME-Version: 1.0" . "\r\n";

$headers.= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

$headers.= "From: ".$values["engineer"]."\n ";
$message.='<table width="100%" border="0">

<tr>

<td height="807"><div align="center"> </div>

<p align="center"><strong>Manual Spares Request
</strong></p> <table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="14%"><strong>Date</strong></td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid"width="40%">'.$date_value.'&nbsp;</td>

</tr>

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid"><strong>ID</strong></td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid">'.$keys["id"].'</td>

</tr>

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid"><strong>Instrument</strong></td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid">'.$values["instrument"].'&nbsp;</td>

</tr>

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid"><strong>Customer</strong></td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid">'.$values["customer"].'</td>

</tr>

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid"><strong>Serial Number</strong></td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid">'.$values["serial_no"].'</td>

</tr>
<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid"><strong>Project Code </strong></td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid">'.$values["projectcode"].''.$values["wcsi"].'</td>
</tr>
</table>

<div align="center">
</div>

<table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="22%"><strong>Ship To </strong></td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="78%">'.$values["shipto"].'&nbsp;</td>

</tr>

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" height="41" colspan="2"><p><strong>Address:-</strong>
'.$values["address1"].'
'.$values["address2"].'
'.$values["address3"].'
'.$values["address4"].'
'.$values["city"].'
'.$values["state"].'
'.$values["zip"].'
'.$values["country"].'

</strong><strong>
</strong></p> </td>

</tr>

</table>



<table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="10%"><strong>Notes:-</strong></td>

<td width="90%">&nbsp;</td>

</tr>

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" colspan="2">'.$values["notes"].'&nbsp;</td>

</tr>

</table>

<table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="23%">'.$values["part_noa"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="72%">'.$values["part_namea"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="5%">'.$values["quantityparta"].'&nbsp;</td>

</tr>

</table>



<table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="23%">'.$values["part_nob"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="72%">'.$values["part_nameb"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="5%">'.$values["quantitypartb"].'&nbsp;</td>

</tr>

</table>



<table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="23%">'.$values["part_noc"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="72%">'.$values["part_namec"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="5%">'.$values["quantitypartc"].'&nbsp;</td>

</tr>

</table>



<table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="23%">'.$values["part_nod"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="72%">'.$values["part_named"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="5%">'.$values["quantitypartd"].'&nbsp;</td>

</tr>

</table>



<table width="90%" border="0" align="center">

<tr>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="23%">'.$values["part_noe"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="72%">'.$values["part_namee"].'&nbsp;</td>

<TD

style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid" width="5%">'.$values["quantityparte"].'&nbsp;</td>

</tr>

</table> </td>

</tr>

</table>';
mail($email, $subject, $message, $headers);

return true;

================
I know that's quite long winded since the email is sent in html code but if I set this in Before record added it works, but doesn't supply the ID (It just doesn't show up) and if I put this in after record added I get an error saying:-
Error type 8

Error description Undefined variable: message
Any ideas please?
Thanks,
Graham

J
Jane 6/19/2009

Hi,
I recommend you to use another variable name (for example $body_message) instead of $message in your code.

$message variable is defined in this event.

G
Greeham author 6/19/2009

Hi,

I recommend you to use another variable name (for example $body_message) instead of $message in your code.

$message variable is defined in this event.


Hi Jane,
That's great thanks, I now have it mailing after record added but still cannot get the ID to show up in the email.
I have tried '.$keys["id"].' and '.$values["id"].' in the html email but both show nothing in the actual email.
Any ideas?
Thanks,

J
Jane 6/19/2009

Graham,
try to use this one:

$id = mysql_insert_id();

G
Greeham author 6/19/2009

Fantastic, it works great now.
Thanks,
Graham