Connecting Tech Pros Worldwide Help | Site Map

PHP EMail Form and set cookie

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 23rd, 2007, 02:05 PM
pete.brooker@gmail.com
Guest
 
Posts: n/a
Default PHP EMail Form and set cookie

Hi,

Being new to PHP & cookies, I am looking to write an email form, where
a user can choose their name from a drop down list, fill in the
content of the email and hit send and the email will be from that
user.

Then the next time they visit the page, I want to be able to read that
cookie and preset the From part of the email from the cookie.

But I have no clue where to start and can't find any examples of the
web.

If anyone can help out or point me at a script that has this I'd be
very grateful.

Many thanks
Pete


  #2  
Old August 23rd, 2007, 03:25 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: PHP EMail Form and set cookie

pete.brooker@gmail.com wrote:
Quote:
Hi,
>
Being new to PHP & cookies, I am looking to write an email form, where
a user can choose their name from a drop down list, fill in the
content of the email and hit send and the email will be from that
user.
>
Then the next time they visit the page, I want to be able to read that
cookie and preset the From part of the email from the cookie.
>
But I have no clue where to start and can't find any examples of the
web.
>
If anyone can help out or point me at a script that has this I'd be
very grateful.
>
Many thanks
Pete
>
It's pretty easy - you can start at:

http://us.php.net/manual/en/features.cookies.php

Just keep in mind you can't control cookie behavior on the browser end.
For instance, my browser is set up to destroy all cookies when I close
it (except for sites I specify).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  #3  
Old August 31st, 2007, 08:55 AM
pete.brooker@gmail.com
Guest
 
Posts: n/a
Default Re: PHP EMail Form and set cookie

Do you have any example code or give me some pointers.

Pretty new to this and not so sure where to start...

Thanks

On Aug 23, 4:21 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
pete.broo...@gmail.com wrote:
Quote:
Hi,
>
Quote:
Being new to PHP & cookies, I am looking to write an email form, where
a user can choose their name from a drop down list, fill in the
content of the email and hit send and the email will be from that
user.
>
Quote:
Then the next time they visit the page, I want to be able to read that
cookie and preset the From part of the email from the cookie.
>
Quote:
But I have no clue where to start and can't find any examples of the
web.
>
Quote:
If anyone can help out or point me at a script that has this I'd be
very grateful.
>
Quote:
Many thanks
Pete
>
It's pretty easy - you can start at:
>
http://us.php.net/manual/en/features.cookies.php
>
Just keep in mind you can't control cookie behavior on the browser end.
For instance, my browser is set up to destroy all cookies when I close
it (except for sites I specify).
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================


  #4  
Old August 31st, 2007, 09:25 AM
Rik Wasmus
Guest
 
Posts: n/a
Default Re: PHP EMail Form and set cookie

On Fri, 31 Aug 2007 10:50:33 +0200, <pete.brooker@gmail.comwrote:
Quote:
On Aug 23, 4:21 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
>pete.broo...@gmail.com wrote:
Quote:
Being new to PHP & cookies, I am looking to write an email form, where
a user can choose their name from a drop down list, fill in the
content of the email and hit send and the email will be from that
user.
>>
Quote:
Then the next time they visit the page, I want to be able to read that
cookie and preset the From part of the email from the cookie.
>>
Quote:
But I have no clue where to start and can't find any examples of the
web.
>>
Quote:
If anyone can help out or point me at a script that has this I'd be
very grateful.
>>
Quote:
Many thanks
Pete
>>
>It's pretty easy - you can start at:
>>
>http://us.php.net/manual/en/features.cookies.php
>>
>Just keep in mind you can't control cookie behavior on the browser end.
> For instance, my browser is set up to destroy all cookies when I close
>it (except for sites I specify).
(topposting fixed)
Quote:
Do you have any example code or give me some pointers.
>
Pretty new to this and not so sure where to start...
In the 'form page':

$from = isset($_COOKIE['from']) ? htmlspecialchars($_COOKIE['from']): '';
echo '<input name="from" value="'.$from.'">';

In the page that sends the email:

if(isset($_POST['from']) && !isset($_COOKIE['from']))
setcookie('from',$_POST['from'],time() + (60 * 60 * 24 * 60), '/');

Keep in mind that the setcookie() function can only be used before ANY
OTHER output. No starting HTML tags, no whitespace, nothing can be sent
before this function.
--
Rik Wasmus

My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
quality is certainly an option.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.