PDA

View Full Version : Using Dreamweaver and PHP to send form results in an email


kristy1129
02-06-2008, 07:07 PM
I followed the tutorial "Using Dreamweaver and PHP to send form results in an email" I have gotten e-mails to sent from it, but it is immediately goes to the confirmation page, not allowing input of data. Can you please help me?
Thank you SOOO much!!! :grin:
Kristy


<body>
<br>
<form action="www.daisyphotography.com/sendresults.php" method="post" name="ContactForm" id="ContactForm">
<p><br>
</p>
<p align="center">
Name <br>
<input type="text" name="name">
</p>
<p align="center">E-mail<br>
<input type="text" name="email">
<br>
<br>
Subject<br>
<input type="text" name="subject">
<br>
<br>
Comments<br>
<textarea name="comments" cols="50" rows="6"></textarea>
<br>
<br>
<input type="submit" name="Submit" value="Submit">
<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'thedaisyco@gmail.com';

// Where to redirect after form is processed.
$url = 'http://www.daisyphotography.com/confirmation.htm';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
</p>
</form>
</body>

kristy1129
02-06-2008, 07:28 PM
nevermind, I got it to work. I didn't realize at first that I needed one page with the html with all of the form things in it and then a sendresults.php page plus the confirmation.htm...Finally, got it working! :grin::lol:

davidj
02-06-2008, 07:28 PM
first you have the PHP inside the body of the page. Although there is nothing wrong with it in terms of it will work you should seperate your php out from your HTML by placing the PHP above the <HTML> tag. This makes it easier to debug and manage.

where you have the following

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

you need to wrap the mail function in a conditional statement

instead use the following


if(isset($_POST)){

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
$refresh = '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

/// you can see im not echoing the <META refresh tag as i am assigning it to a var. You echo the var in the <head tags where it belongs.

}

in its current state the page will send an email once loaded which is a bad thing as you are sending empty values

kristy1129
02-06-2008, 07:33 PM
Thanks! :o)

davidj
02-06-2008, 07:34 PM
no probs

welcome to the forum

kristy1129
02-06-2008, 07:38 PM
Thanks! This is a great place!!
I don't know if I should start a new thread or if you could just help me...but I'm looking to have a picture on a page and have that picture randomly rotate through a bunch of pictures that are uploaded to a specific folder. So, you can upload pictures to this folder without having to then change anything to show that picture. I believe this can be done in php but I can't get it to work. Can you help?
Thanks!
Kristy

davidj
02-06-2008, 07:44 PM
see if you can understand this...

http://www.dreamweaverclub.com/forum/showthread.php?t=26045&highlight=random+images

one of our regulars (tux i think) wrote a nice one in javascript but i cant find it

if you have any problems with it post a new thread please

try searching the forum as well. We have a lot of solutions gathering dust