This topic is locked

Email Button on View Page

4/6/2008 9:28:49 AM
PHPRunner General questions
N
nix386 author

Can anyone help me with this one? I am learning MySQL and PHP but have limited skill...
What I am trying to do is add a 'Send Email' Button on the View Page using visual editor then using the EVENT 'View Page:before process'.

When a user clicks the send email button on the view page, it emails the current record view and the user name of who clicked the button it to the admin (static email).

After all the time I have wasted on this I would be prepared to donate my kidney for a solution....Am I doing this all wrong?
Here is my code.
//code for the button

echo "<INPUT class=button type=button value=\"&nbsp;&nbsp;Send Email Notification&nbsp;&nbsp;\" onclick='window.location=\"TableName_view.php?editid1=".$_REQUEST["editid1"]."&mail=yes\"'>";
//code for View Page:before process

global $conn;

$str = "select * from TableName where ID=".$_REQUEST["editid1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

if ($_REQUEST["mail"]=="yes")

{

// ** Send email ****

$adminemail="admin@email.com";

$useremail = $data["useremail"];

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";

mail($adminemail, $subject, $message);

mail($useremail, $subject, $message);

//** Redirect to another page ****

header("Location: TabkeName_list.php");

exit();

}

J
Jane 4/7/2008

Hi,
here are some remarks:

global $conn;

//select all values from this view page

$str = "select * from TableName where ID=".$_REQUEST["editid1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

if ($_REQUEST["mail"]=="yes")

{

// ** Send email ****

$adminemail="admin@email.com";



//you need to select useremail from login table here

$str2 = "select EmailField from LoginTable where Username='".$_SESSION["UserID"]."'";

$rs2 = db_query($str2,$conn);

$data2 = db_fetch_array($rs2);

$useremail = $data2["EmailField"];



foreach($data as $field=>$value)

$message.= $field." : ".$value."\r\n";
mail($adminemail, $subject, $message);

mail($useremail, $subject, $message);

//** Redirect to another page ****

header("Location: TableName_list.php");

exit();

}

N
nix386 author 4/7/2008

Ah I see what I was doing now thanks Jane.

The help is greatly appreciated!

R
rainerwolf 9/19/2008

Hello Jane, i tried this code and i've got follwing error message:
Fehlerbeschreibung Undefined variable: message

URL localhost/oe/Copy_of_oe_vorgang1_view.php?editid1=1&mail=yes
PHP code Snippet Email Button:
echo "<INPUT class=button type=button value=\"&nbsp;&nbsp;Send Email Notification&nbsp;&nbsp;\" onclick='window.location=\"Copy_of_oe_vorgang1_view.php?editid1=".$_REQUEST["editid1"]."&mail=yes\"'>";
and additionally the following code is in the before process event:
global $conn;
$str = "select * from oe_vorgang1 where ID=".$_REQUEST["editid1"];
$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
if ($_REQUEST["mail"]=="yes")

{

$adminemail="mail@testmail.de";
foreach($data as $field=>$value)

$message.= $field." : ".$value."\r\n";
mail($adminemail, $subject, $message);
header("Location: Copy_of_oe_vorgang1_list.php");

exit();

}
What is wrong?
Rainer

J
Jane 9/19/2008

Rainer,
try to use this one:

global $conn;

$message = "";

$str = "select * from oe_vorgang1 where ID=".$_REQUEST["editid1"];
$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
if ($_REQUEST["mail"]=="yes")

{

$adminemail="mail@testmail.de";
foreach($data as $field=>$value)

$message.= $field." : ".$value."\r\n";
mail($adminemail, $subject, $message);
header("Location: Copy_of_oe_vorgang1_list.php");

exit();

}

R
rainerwolf 9/19/2008

Thank you yery much, Jane, it works great. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=33221&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=33221&image=2&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />
Please, can you tell me, what i must do, if i want to attach a PDF File in this email function?