This topic is locked

How to put a field value in the From: Header in reply to mail.

2/13/2008 2:58:13 PM
PHPRunner General questions
M
mmponline author

I use this as part of my mail event.
mail($email, $subject, $message, 'From: MMP Projects <mmp@mmponline.co.za>');
Is there a way to put a field value in the place of the e-mail address so that the reply email will go to a field value where different e-mails were pasted:
mail($email, $subject, $message, 'From: MMP Projects [code]]<email field here>[/code');

J
Jane 2/14/2008

Stephan,
all field values are stored in the $values array on the Before record added/updated and After record added/updated events:

mail($email, $subject, $message, 'From: MMP Projects <".$values["FieldName"].">');

M
mmponline author 2/14/2008

Jane
I'm sure this will work. In this instance, however, the reply e-mail lies in another table (master table of this details one), This makes it more complicated.
Eg.

TableA - has the reply address in email field.

TableB (detail of A) has the event after add to send an email and when user reply to this mail, it must reply to the address on TableA's email field.
Hope my explanation makes sense.

M
mmponline author 2/16/2008

Any help here?

S
smcgo4 2/18/2008

Any help here?


Here is what I do:
// If action is Think Tank

//** Insert a record into another table ****

if ($values["SuggestedAction"]==6)

{

global $conn;
$str = "INSERT INTO thinktank (StudentId, ReferDate) values (";
$str .= $values["StudentID"];

$str .= ",'";

$str .= $values["IncidentDateandTime"];

$str .= "')";
db_exec($str,$conn);
}
// Set the email to HTML

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//** Send email to class teacher ****

global $conn;

$str = "SELECT Email from staff WHERE `StaffID` = '".$values["TeacherID"]."'";

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

$data = db_fetch_array($rs);
// Look up the Suggested Action Code

$str = "Select Action from `actions` WHERE Id = '".$values["SuggestedAction"]."'";

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

$adata = db_fetch_array($rs);
// Look up Student Name

$str = "SELECT concat(students.FirstName,' ',students.LastName) as FullName from students WHERE `Id` = '".$values["StudentID"]."'";

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

$sdata = db_fetch_array($rs);
//Prepare email

$email = "".$data["Email"]."";

$message="";

$subject="New behaviour data record for: '".$sdata["FullName"]."'";
foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
// Add the Suggested Action as a descriptor as well as the ID

$message.=$adata["Action"];
mail($email, $subject, $message, $headers);
//** Send email to admin ****

$email="the.principal@xxx.xx.edu.au";

$message="";
foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
// Add the Suggested Action as a descriptor as well as the ID

$message.=$adata["Action"];
// Add the student's name

$message.=$sdata["Fullname"];
mail($email, $subject, $message, $headers);
return true;

M
mmponline author 2/18/2008

The reply e-mail must go to the responsible person of the project, but the address lies in another table. The event I use to send a copy to this person is:
//select project email from Projects Table
global $conn,$strTableName;

$email = "";

$str = "select RPmail1 from MMPProjects where ProjID=".$_SESSION[$strTableName."_masterkey1"];

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

if ($data = db_fetch_array($rs))

$email = $data["RPmail1"];
Now when one of the other people in my list of recepients reply to the sent e-mail, I need the reply e-mail to be the RPmail1 field's content.
Something like: mail($email, $subject, $message, 'From: MMP Projects <".$values["RPmail1"].">'); ...but this info must be drawn from the MMPProjects table...

J
Jane 2/18/2008

Stephan,
yuo code looks correct.
Try to print your SQL query and email value before sending email:

global $conn,$strTableName;

$email = "";

$str = "select RPmail1 from MMPProjects where ProjID=".$_SESSION[$strTableName."_masterkey1"];

echo $str;

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

if ($data = db_fetch_array($rs))

$email = $data["RPmail1"];

echo $email;

M
mmponline author 2/18/2008

I get the following error with above code:
select RPmail1 from MMPProjects where ProjID=

PHP error happened
Technical information

Error type 256

Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

URL mmponline.co.za/projects/CompletedMMPProjectProgress_add.php?

Error file /usr/www/users/mmpo/projects/include/dbconnection.php

Error line 26

SQL query insert into `MMPProjectProgress` (`ProgressID`, `Date`, `PostedBy`, `Status`, `Comment`, `NextAction`, `AlsoNotify1`, `AlsoNotify2`) values (null, '2008-02-18 23:00:40', 'Stephan', 'E-mail To Client', 'test', '', '', '')

Solution This is a general error. It occurs when thereis an error in event code or in SQL.
Send your SQL or event code along with full error message tosupport@xlinesoft.com.
and the mail line:

mail($email, $subject, $message, 'From: MMP Projects <".$values["RPmail1"].">');
J
Jane 2/19/2008

Stephan,
make sure that $_SESSION[$strTableName."_masterkey1"] is filled.

Also make sure you go to the detail page through master page.
I can't verify each line of your code.