From: Jim Lucas on
Joe Jackson wrote:
> Hi
>
> All I need is in the message body of the email is to include more data from
> the form. At present it only displays the 'message' field value in the body
> of the email. I need to add further information into the email from the
> form such as 'address' 'name' and 'telephone number'
> When I have tried to add them into the PHP script

Bostjan already gave you the answer.

But, here is another example of how I do it. It is VERY raw...

mail('email(a)address.com', 'Subject', print_r($values, 1), "From...");

It isn't pretty, but it works. I have a cron job that emails every 5 minutes
with results formated by the print_r() function. It will take everything you
have in $values and print it out formated in a nested table like structure.



>
> $values['message'], ['name'], ['address'], ['telephonenumber'],
>
> I am getting PHP errors, what would be the correct syntax I would need to
> use to get the following form field values into the email body.
>
> I greatly appreciate all your expert advice and help.
>
>
> On Sun, Sep 19, 2010 at 11:37 PM, TR Shaw <tshaw(a)oitc.com> wrote:
>
>> On Sep 19, 2010, at 6:00 PM, Joe Jackson wrote:
>>
>> Hi
>>
>> Sorry for the simple question but I am trying to get my head around PHP. I
>> have a sample PHP script that I am trying to use to send a php powered
>> email
>> message. The snippet of code is shown below....
>>
>> mail('email(a)address.com', 'Subject', $values['message'], "From:
>> \"{$values['name']}\" <{$values['emailaddress']}>");
>>
>> This works fine, but how can I add in other fields to the email that is
>> recieved?
>>
>> For example in the form there are fields called, 'emailaddress',
>> 'telephone', 'address' and 'name' which I need to add into the form along
>> with the message field
>>
>> Also with the formatting how can I change the format of the email to
>>
>> Name: $values['name'],
>> Address: etc
>> Message:
>>
>>
>> Joe
>>
>> The mail command lets you send mail (an RFC2821 envelop). The function is:
>>
>> bool *mail* ( string $to , string $subject , string $message [, string
>> $additional_headers [, string$additional_parameters ]] )
>>
>> $to is where you want it to go
>> $subject is whatever you want the subject to be
>> $message is the information you want to send
>> Ignore the other parameters unless you are very familiar with RFCs 2821,
>> 2822 and their associated RFCs
>>
>> So if you want to send info from a form you might want to roll it up in xml
>> and send it via the message part. when you receive it you can easily decode
>> it. If you don't want to do that put it in a format that you can easily
>> decode on the receiving end.
>>
>> Basically "mail" is a way to deliver information in the $message body. How
>> you format the information there is up to you. However, depending on your
>> system's config you are probably constrained to placing only 7bit ascii in
>> the $message body.
>>
>> You might also move away from the mail function and look at phpmailer at
>> sf.net if you need more complex capabilities.
>>
>> Tom
>>
>>
>>
>>
>

From: chris h on
> Ignore the other parameters unless you are very familiar with RFCs 2821,
> 2822 and their associated RFCs
>


I would advise against ignoring the other parameters. Doing so will pretty
much guarantee having your email end up in SPAM. Instead look up the
examples in the docs, or better yet use something like phpmailer as Tom
suggested.


Chris.


On Sun, Sep 19, 2010 at 6:37 PM, TR Shaw <tshaw(a)oitc.com> wrote:

>
> On Sep 19, 2010, at 6:00 PM, Joe Jackson wrote:
>
> > Hi
> >
> > Sorry for the simple question but I am trying to get my head around PHP.
> I
> > have a sample PHP script that I am trying to use to send a php powered
> email
> > message. The snippet of code is shown below....
> >
> > mail('email(a)address.com', 'Subject', $values['message'], "From:
> > \"{$values['name']}\" <{$values['emailaddress']}>");
> >
> > This works fine, but how can I add in other fields to the email that is
> > recieved?
> >
> > For example in the form there are fields called, 'emailaddress',
> > 'telephone', 'address' and 'name' which I need to add into the form along
> > with the message field
> >
> > Also with the formatting how can I change the format of the email to
> >
> > Name: $values['name'],
> > Address: etc
> > Message:
> >
>
> Joe
>
> The mail command lets you send mail (an RFC2821 envelop). The function is:
>
> bool mail ( string $to , string $subject , string $message [, string
> $additional_headers [, string$additional_parameters ]] )
>
> $to is where you want it to go
> $subject is whatever you want the subject to be
> $message is the information you want to send

Ignore the other parameters unless you are very familiar with RFCs 2821,
> 2822 and their associated RFCs


> So if you want to send info from a form you might want to roll it up in xml
> and send it via the message part. when you receive it you can easily decode
> it. If you don't want to do that put it in a format that you can easily
> decode on the receiving end.
>
> Basically "mail" is a way to deliver information in the $message body. How
> you format the information there is up to you. However, depending on your
> system's config you are probably constrained to placing only 7bit ascii in
> the $message body.
>
> You might also move away from the mail function and look at phpmailer at
> sf.net if you need more complex capabilities.
>
> Tom
>
>
>
>
From: J Ravi Menon on
Just on this topic, I found swiftmailer library to be really useful
esp. in dealing with 'template' emails with custom variables per
recipient:

http://swiftmailer.org/

The e.g. on email template processing:

http://swiftmailer.org/docs/decorator-plugin-howto

There are batchSend() functionalities, ability to compose various mime
type emails etc...

Ravi

On Mon, Sep 20, 2010 at 8:20 AM, chris h <chris404(a)gmail.com> wrote:
>> Ignore the other parameters unless you are very familiar with RFCs 2821,
>> 2822 and their associated RFCs
>>
>
>
> I would advise against ignoring the other parameters.  Doing so will pretty
> much guarantee having your email end up in SPAM.  Instead look up the
> examples in the docs, or better yet use something like phpmailer as Tom
> suggested.
>
>
> Chris.
>
>
> On Sun, Sep 19, 2010 at 6:37 PM, TR Shaw <tshaw(a)oitc.com> wrote:
>
>>
>> On Sep 19, 2010, at 6:00 PM, Joe Jackson wrote:
>>
>> > Hi
>> >
>> > Sorry for the simple question but I am trying to get my head around PHP.
>>  I
>> > have a sample PHP script that I am trying to use to send a php powered
>> email
>> > message.  The snippet of code is shown below....
>> >
>> >    mail('email(a)address.com', 'Subject', $values['message'], "From:
>> > \"{$values['name']}\" <{$values['emailaddress']}>");
>> >
>> > This works fine, but how can I add in other fields to the email that is
>> > recieved?
>> >
>> > For example in the form there are fields called, 'emailaddress',
>> > 'telephone', 'address' and 'name' which I need to add into the form along
>> > with the message field
>> >
>> > Also with the formatting how can I change the format of the email to
>> >
>> > Name: $values['name'],
>> > Address: etc
>> > Message:
>> >
>>
>> Joe
>>
>> The mail command lets you send mail (an RFC2821 envelop). The function is:
>>
>> bool mail ( string $to , string $subject , string $message [, string
>> $additional_headers [, string$additional_parameters ]] )
>>
>> $to is where you want it to go
>> $subject is whatever you want the subject to be
>> $message is the information you want to send
>
> Ignore the other parameters unless you are very familiar with RFCs 2821,
>> 2822 and their associated RFCs
>
>
>> So if you want to send info from a form you might want to roll it up in xml
>> and send it via the message part. when you receive it you can easily decode
>> it. If you don't want to do that put it in a format that you can easily
>> decode on the receiving end.
>>
>> Basically "mail" is a way to deliver information in the $message body. How
>> you format the information there is up to you. However, depending on your
>> system's config you are probably constrained to placing only 7bit ascii in
>> the $message body.
>>
>> You might also move away from the mail function and look at phpmailer at
>> sf.net if you need more complex capabilities.
>>
>> Tom
>>
>>
>>
>>
>
From: Joe Jackson on
Hi

I am trying the following snippet as Bostjan suggested, and an email is
getting sent when I submit the form however in the body of the email I am
getting none of the form data in the body of the email. All I am getting is
the letter 'z' ? Also in the from field of the email this is showing as my
email address and not the email address of the user who has sent the form

Any ideas on where I am going wrong with this snippet? Any advice would be
much appreciated


$msgContent = "Name: ". $values['name'] ."\n";
$msgContent .= "Address: ". $values['address'] ."\n";
$msgContent .= "Telephone: ". $values['telephone'] ."\n";
$msgContent .= "Email Address: ". $values['emailaddress'] ."\n";
$msgContent .= "Message: ". $values['message'] ."\n";

function ProcessForm($values)
{
mail('myemail:domain.com', 'Website Enquiry', $msgContent, "From:
\"{$values['name']}\" <{$values['emailaddress']}>");

// Replace with actual page or redirect :P
echo "<html><head><title>Thank you!</title></head><body>Thank
you!</body></html>";
From: J Ravi Menon on
On Wed, Sep 29, 2010 at 1:37 PM, Joe Jackson <priorybar(a)googlemail.com> wrote:
> Hi
>
> I am trying the following snippet as Bostjan  suggested, and an email is
> getting sent when I submit the form however in the body of the email I am
> getting none of the form data in the body of the email.  All I am getting is
> the letter 'z' ?  Also in the from field of the email this is showing as my
> email address and not the email address of the user who has sent the form
>
> Any ideas on where I am going wrong with this snippet?  Any advice would be
> much appreciated
>
> $msgContent = "Name: ". $values['name'] ."\n";
> $msgContent .= "Address: ". $values['address'] ."\n";
> $msgContent .= "Telephone: ". $values['telephone'] ."\n";
> $msgContent .= "Email Address: ". $values['emailaddress'] ."\n";
> $msgContent .= "Message: ". $values['message'] ."\n";
>
> function ProcessForm($values)
> {
>     mail('myemail:domain.com', 'Website Enquiry', $msgContent, "From:
> \"{$values['name']}\" <{$values['emailaddress']}>");
>
>      // Replace with actual page or redirect :P
>     echo "<html><head><title>Thank you!</title></head><body>Thank
> you!</body></html>";

Not sure if it it is a typo above, are you actually passing
$msgContent in the function above? If it is a global variable, you
would need to add a 'global' declaration:

function ProcessForm($values)
{
global $msgContent;

mail('myemail:domain.com', 'Website Enquiry', $msgContent, "From:
\"{$values['name']}\" <{$values['emailaddress']}>\r\n");
..
..
..
}

Also try adding CRLF sequence at the end of the header line as shown above.

Ravi