Help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
longbo43
Forum Newbie
Posts: 10
Joined: Tue Apr 20, 2010 2:33 am

Help needed

Post by longbo43 »

I am a complete novice but have managed to write a PHP form (albiet using PHPRunner) to allow sales people to enter their meeting request information and then this is fwd to a MySQL database and then an access db program.

I have been requested to change the format of the email that is sent to confirm receipt of the request.

The section in the php file that I think adds the text to the body of the email seems to run through the array and each cell entry is added as a new line of text.

What I need to do is add certain lines in as a specific section.

For example I need to have all sales person details in a section at the top of the email, then a couple of empty lines, a dotted line, then a couple of spaces then another section which might be about the person they are looking to meet with, then another break and then another section and so on. Probably be about 5 sections to do this for.

The code I think is being used at the moment does not seem to allow for this formatting and is below.

Any help would be appreciated. Also if more info is need please just ask and I will provide.

Code: Select all


function BeforeAdd(&$values,&$message,$inline)
{


//**********  Send email with new data  ************

$email=$values["**********_Email"];
$from=$values["**********_Email"];
$cc="*********@********************.com"; 

$link = mysql_connect("www.***************.com", "**********", "***********");
mysql_select_db("request_mtg", $link);
 
$result = mysql_query("SELECT * FROM ******************", $link);
$rows = mysql_num_rows($result); 
$lastID=$rows + 1;
//$lastID=mysql_query($rows) + 1;


$msg="If you have any questions, please contact ****** ********* at *****@*************.com or by phone at *******************.\n\nMeeting ID: $lastID.\n";
$subject="Meeting Request ID ".$lastID.", ".$values["Operator"].", ".$values["Target1_Contact_Surname"];

foreach($values as $field=>$value)
{
	if(!IsBinaryType(GetFieldType($field)))
	$msg.= $field." : ".$value."\r\n";
}
	
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from' => $from, 'cc' => $cc));
if(!$ret["mailed"])
echo $ret["message"];




return true;
;
} // function BeforeAdd

User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Help needed

Post by Benjamin »

:arrow: Moved to PHP Code
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Help needed

Post by McInfo »

These are the lines to focus on:

Code: Select all

foreach($values as $field=>$value)
{
    if(!IsBinaryType(GetFieldType($field)))
        $msg.= $field." : ".$value."\r\n";
}
You will need to replace the foreach loop with some different code. But first...

How are the functions GetFieldType() and IsBinaryType() defined? You may or may not need to use them.

Please provide some sample data for $values. Submit the form and look at the result of

Code: Select all

print_r($values);
In the sample data, look for field names. Without the foreach loop, you will need to reference each field directly with a field name (rather than indirectly with the $field variable). For example,

Code: Select all

$msg .= "Example: " . $values['example_field'] . "\r\n";
longbo43
Forum Newbie
Posts: 10
Joined: Tue Apr 20, 2010 2:33 am

Re: Help needed

Post by longbo43 »

Hi

Firstly to the mod - sorry for posting in the wrong place.

Secondly thanks for the response. What you have said has gone over my head but I did get the gist. You are suggesting that I enter each form field in as a seperate piece of code rather than looping. It will take ages!!!!! There are 117 entry fields on the form.
Is there any way to break the page up into sections then loop through those sections in the order I require?

CHeers for any help
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Help needed

Post by McInfo »

In the the email that is currently generated, do the name-value pairs appear in the same order as they would in the new format?

Does the additional formatting consist of only inserting blank lines and a dotted line between certain lines?
longbo43
Forum Newbie
Posts: 10
Joined: Tue Apr 20, 2010 2:33 am

Re: Help needed

Post by longbo43 »

Hi Thank you for you reply and sorry it has been months since I have looked at this.

The boss decided that as it was too much work just leave it, But.......

Now the client has come back and said they want it changed.

In answer to your question the form fields order needs to be changed with certain ones being grouped together so I think that means I need to add then in individually.

If I am wrong then please correct me.

Cheers
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Help needed

Post by McInfo »

Without seeing the actual data, I would just be guessing about ways to make the task easier. Unless you can find a repeating subpattern within the overall pattern of the format, you will probably have to do each line individually.

Maybe an email template stored in a text file and containing placeholders would make things easier. Just do string replacements on the placeholders.
Post Reply