Email Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
verbena
Forum Newbie
Posts: 4
Joined: Thu Nov 23, 2006 6:35 am

Email Form

Post by verbena »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am not a coder, I have some code that allows a user to send an email via a Form. I have used the code on a couple of sites with no trouble

It goes from a contact form, click submit , this will take it to send.php then it will either take it to error.htm or success.htm

I have just tried to use it in another site and when I ckick submit it takes me to send.php whith a "page not available" message and the send.php page will open on my computer in dreamweaver.

this is the code for the contact form

[syntax="html"]<form name="form1" method="post" action="send.php">
        <table width="600" border="0" cellspacing="10" cellpadding="0">
          <tr>
            <td class="Normal"><div align="right"></div></td>
            <td><div align="left">
              <p class="Head">Contact Us </p>
            </div></td>
          </tr>
          <tr>
            <td class="Normal"><div align="right"><span class="red">*</span>Name</div></td>
            <td><div align="left">
              <input name="Name" type="text" id="Name">
            </div></td>
          </tr>
          <tr>
            <td class="Normal"><div align="right"><span class="red">*</span>Email</div></td>
            <td><div align="left">
              <input name="Email" type="text" id="Email">
              
            </div></td>
          </tr>
          <tr>
            <td valign="top" class="Normal"><div align="right">Comments</div></td>
            <td><div align="left">
              <textarea name="Comment" cols="50" rows="10" id="Comment"></textarea>
            </div></td>
          </tr>
          <tr>
            <td class="Normal"><div align="right">
              <input type="submit" name="Submit" value="Submit">
            </div></td>
            <td><div align="left">
              <input name="Reset" type="reset" id="Reset" value="Reset">
</div></td>
          </tr>
        </table>
      </form>



Then the send.php code[/syntax]

Code: Select all

<?PHP

error_reporting(7);


if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
 $ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
 $ClientIP = $_SERVER['REMOTE_ADDR'];
}

# RegisterGlobals OFF

$FTGName = $_POST['Name'];

$FTGEmail = $_POST['Email'];
$FTGComment = $_POST['Comment'];
$FTGSubmit = $_POST['Submit'];
$FTGReset = $_POST['Reset'];


if (get_magic_quotes_gpc) {
 $FTGName = stripslashes($FTGName);
 
 $FTGEmail = stripslashes($FTGEmail);
 $FTGComment = stripslashes($FTGComment);
 $FTGSubmit = stripslashes($FTGSubmit);
 $FTGReset = stripslashes($FTGReset);
}
# Redirect user to the error page

if ($validationFailed == true) {

 header("Location: error.htm");
 exit;

}

# Email to Form Owner

$emailTo = '"" <myemail@yahoo.com.au>';

$emailSubject = "From website";
$emailSubject = preg_replace('/[\x00-\x1F]/', '', $emailSubject);

$emailFrom = "$FTGEmail";
$emailFrom = preg_replace('/[\x00-\x1F]/', '', $emailFrom);

$emailHeader = "From: $emailFrom\n"
 . "Reply-To: $emailFrom\n"
 . "MIME-Version: 1.0\n"
 . "Content-Type: multipart/alternative; boundary="FTG_BOUNDRY"\n"
 . "X-Sender: $emailFrom\n"
 . "X-Mailer: PHP\n"
 . "X-Priority: 3\n"
 . "Return-Path: $emailFrom\n"
 . "\n";

$emailBody = "--FTG_BOUNDRY\n"
 . "Content-Type: text/plain; charset="ISO-8859-1"\n" 
 . "Content-Transfer-Encoding: 8bit\n"
 . "\n"
 . "Name: $FTGName\n"
 
 . "Email: $FTGEmail\n"
 . "Comment: $FTGComment\n"
 . "Submit: $FTGSubmit\n"
 . "Reset: $FTGReset\n"
 . "\n"
 . ""
 . "\n"
 . "--FTG_BOUNDRY\n"
 . "Content-Type: text/html; charset="ISO-8859-1"\n"
 . "Content-Transfer-Encoding: base64\n"
 . "\n"
 . chunk_split(base64_encode("<HTML>\n"
 . "<head>\n"
 . "<title></title>\n"
 . "</head>\n"
 . "<body>\n"
 . "<table width="500" border="0" cellspacing="0" cellpadding="3">\n"
 . "  <tr>\n"
 . "    <td width="150"><div align="right"><b><font face="Tahoma" size="2">Name:</font></b></div></td>\n"
 . "    <td width="336"><font face="Tahoma" size="2">$FTGName</font></td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 
 . "    <td width="150"><div align="right"><b><font face="Tahoma" size="2">Email:</font></b></div></td>\n"
 . "    <td><font face="Tahoma" size="2">$FTGEmail</font></td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td width="150"><div align="right"><b><font face="Tahoma" size="2">Comment:</font></b></div></td>\n"
 . "    <td><font face="Tahoma" size="2">$FTGComment</font></td>\n"
 . "  </tr>\n"
 . "</table></body></html>\n"
 . "\n"
 . ""))
 . "\n"
 . "--FTG_BOUNDRY--";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

# Redirect user to success page

header("Location: success.htm");
exit;

# End of PHP script
?>


If any one can help it would be much appreciated

Thank you


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

You know that PHP has to parsed by the server
and to use PHP you need the script to reside on a server
verbena
Forum Newbie
Posts: 4
Joined: Thu Nov 23, 2006 6:35 am

Post by verbena »

Hi
No I didn't know that, as I said Im not really a coder. I am just copy and past from another project. Could you explain what you mean please...
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

PHP will only run on a server such as apache Both PHP and apache are freely available to download from the web
PHP here http://www.php.net/ and Apache http://www.apache.org/dyn/closer.cgi
A server is used to host a website to use PHP pages even on your own machine you will need to install web server software it can be a little complicated to set up but there are plenty of tutorials like these here --->>> http://www.ricocheting.com/server/

if you dont want to tdo this you will have to sign up with a provider for some webspace
verbena
Forum Newbie
Posts: 4
Joined: Thu Nov 23, 2006 6:35 am

Post by verbena »

I have tried the same code on a different server. When I clicked the submit button it again sent me to "send.php and a message saying page not exist it should have sent it to success.htm.
However the email was sent through ok.

So this code seems to work fine on one website, I copy and paste it to another server and it doesn't work. I put it on another server and it kind of works????
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

means that it cant find sucess.htm on the server

the sucess file is only a confirmation page and doesnt perform any other function
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Header level redirection requires using full URLs to the destination. This is apart of the HTTP standard.
verbena
Forum Newbie
Posts: 4
Joined: Thu Nov 23, 2006 6:35 am

Post by verbena »

So does that mean it depends on what level your site is on the server, that is why this code works on some servers and not others?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I don't understand why HTML coders get neck-deep in PHP just to send simple emails from forms.

Code: Select all

<form action="mailto:your.email@domain.com" method="post">
  <input type="text" name="message" />
  <input type="submit" />
</form>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

jayshields wrote:I don't understand why HTML coders get neck-deep in PHP just to send simple emails from forms.

Code: Select all

<form action="mailto:your.email@domain.com" method="post">
  <input type="text" name="message" />
  <input type="submit" />
</form>
Ouch... don't swear on this forum please ;) mailto isn't great. It only works if: a) The client has an email client installed b) The browser is linked with that e-mail client

Add to that the fact that you usually need to click send once the email client opens.

It's obviously an option, but I'd certainy favour PHP.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Yeah, I'm aware of that, and I could've guessed you'd favor PHP: afterall you have developed your own emailing library in PHP!

I think I'd rather give those misconviniences (is that a word?) to the user than learn a new programming language.
Post Reply