Skip to main content
Inspiring
March 22, 2007
Answered

<?php mail.. position question

  • March 22, 2007
  • 3 replies
  • 356 views
Fairly standard question that I have noticed lots of .asp comments on forum.

I have a registration form that inserts a record and then re-directs to a register success page.

I also want the registersuccess page (or alternatively form page) to automatically send an e-mail to me, including certain information entered into the form fields - namely the unique identifier (email address). This I can set as a hyperlink to allow me to connect directly to that record on-line.

I've sussed that this is the line I want to use in the registersuccess page:

<?php mail ("me@work.co.uk", "There is a new Site Registration", $email);?>

Call me stupid but I cannot work out how to propogate "$email" from a form field variable in the previous page if no information is being passed from the previous page.

I have tried to include ?EMAIL=<?php echo $POST_VARS['emailtextfield'];?> into the redirection address when the form is submitted but I get an error.

I am now trying to find out where I can put my "mail" code in the first form page but am having great difficulty as it is now complicated by form checks and duplicate checks.

Can anyone help?
This topic has been closed for replies.
Correct answer Newsgroup_User
On 22 Mar 2007 in macromedia.dreamweaver.appdev, RichardODreamweaver
wrote:

> I am now trying to find out where I can put my "mail" code in the
> first form page but am having great difficulty as it is now
> complicated by form checks and duplicate checks.

In the script which processes the form (<form method="POST"
action="thisisthefileyouwant.php">), find where the insert behavior
ends. Just after that, you put your code to send the email to you.
The visitor's entered email will still be in $_POST['emailFieldName'].
So:

<?php
// ...
// Code to insert data ends here
$to = 'me@example.com';
$subject = 'Record inserted';
$body = 'This record was inserted: EMail: ' . $_POST['emailFieldName'];

mail($to, $subject, $body);
?>

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php

3 replies

Inspiring
March 26, 2007
On 26 Mar 2007 in macromedia.dreamweaver.appdev, RichardODreamweaver
wrote:

> I put it as you can see below and it seems to work but DW has a
> funny and says that the insert behaviour was partially deleted! The
> insert behaviour in the behaviour panel has now also dissapeared.

DW gets funny about you playing with its behaviors. If it works, go with
it. Understand, though, that from now on, you're stuck editing the
insert behavior by hand.

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php
Inspiring
March 26, 2007
Thanks Joe

I put it as you can see below and it seems to work but DW has a funny and says that the insert behaviour was partially deleted! The insert behaviour in the behaviour panel has now also dissapeared.

Is the position correct?

.........
$insertGoTo = "/regsuccess.php";

$BODY= 'This record was inserted -EMail: ' . $HTTP_POST_VARS['textfieldemail'];
mail ("me@work.co.uk", "There is a new Site Registration", $BODY);

if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));

etc. etc....
Newsgroup_UserCorrect answer
Inspiring
March 22, 2007
On 22 Mar 2007 in macromedia.dreamweaver.appdev, RichardODreamweaver
wrote:

> I am now trying to find out where I can put my "mail" code in the
> first form page but am having great difficulty as it is now
> complicated by form checks and duplicate checks.

In the script which processes the form (<form method="POST"
action="thisisthefileyouwant.php">), find where the insert behavior
ends. Just after that, you put your code to send the email to you.
The visitor's entered email will still be in $_POST['emailFieldName'].
So:

<?php
// ...
// Code to insert data ends here
$to = 'me@example.com';
$subject = 'Record inserted';
$body = 'This record was inserted: EMail: ' . $_POST['emailFieldName'];

mail($to, $subject, $body);
?>

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php