Page 1 of 1

Adding multiple $message strings in a mail() function

Posted: Thu Feb 07, 2008 4:18 am
by lshstech
Hi I have created a PHP front end to my Filemaker database that allows a user to enter details into a form that adds it to the database and then displays a confirmation page with the details that have been entered.

In the confirmation page code I have added the following code that sends an email with details from the record displayed in the confirmation page. Here is the code below:

-----------------------------------------------------------------------------------------------------------------------
<?php
ini_set("SMTP","10.99.240.12");
ini_set("smtp_port",25);


mail(
$to = 'sbainbridge@lshs.org.uk',
$subject = 'Network logon: '. $record->getField('Network logon', 0),
$message = 'E1 Username:'. $record->getField('E1 Username', 0),
$headers = 'From: ictservices@lshs.org.uk'."\r\n"
);
?>
----------------------------------------------------------------------------------------------------------------------
I would like to add more data from fields in the record in the confirmation php page but this is where I get syntax errors. I have tried adding the following line below the highlighted line in my code.

$message = 'Details:'. $record->getField('details', 0),

When this is entered I get a syntax error and no email is sent. The PHP code sends an email fine without this line added but I would like add multiple fields from my databse record to the message part of the email.

Any help will be well appreciated!

Thanks

Simon :banghead:

Re: Adding multiple $message strings in a mail() function

Posted: Thu Feb 07, 2008 4:46 am
by mattis2k
You have to build the $message string before passing it to mail()

eg

Code: Select all

 
$message = 'E1 Username:'. $record->getField('E1 Username', 0);
$message .= 'Details'. $record->getField('details', 0);
 
mail($to, $subject,$message, $headers);
 
 
Matt

Re: Adding multiple $message strings in a mail() function

Posted: Thu Feb 07, 2008 5:25 am
by lshstech
Hi thanks for your help, I found that the following code works:

$message = 'E1 Username:'. $record->getField('E1 Username', 0). 'Details:'. $record->getField('Details', 0),

This emails me both fields which is great.

Do you know I can put a line break in so that I can separate the data onto different lines in a email message?

i.e. E1 Username: username here
Details: Problem details here

Cheers Simon

Re: Adding multiple $message strings in a mail() function

Posted: Thu Feb 07, 2008 5:44 am
by lshstech
I solved the line break problem as shown below:

$message = 'E1 Username:'. $record->getField('E1 Username', 0)."\n". 'Details:'. $record->getField('Details', 0),

This will obviously get big and messy as I add more fields to this string. How do I construct this outside the function and pass it back into the function.

Thanks

Simon