Contact form "thank you" page & post it?

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
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Contact form "thank you" page & post it?

Post by akjackson1 »

I want to make a form f=do two things at once, They work fine by them selves but thanking a person after sending a form and not ever sending it to and email is silly!

I have this code to send the mail:

Code: Select all

<?php include("thank you.php"); ?>
<?php
  $name = $_POST['name'] ;
  $email = $_POST['email'] ;
  $message = $_POST['message'] ;
 
 
  mail( "akjackson1@gmail.com", "Contact Form", "Name: ". $name . "\r\n\r\n". "Email: " . $email . "\r\n\r\n" . "Message: ". $message . "\r\n\r\n". "Mailing List: ". $mailinglist, "From: $email" );
?>
And this "thank you" page:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Message sent successfully</title>
<meta http-equiv="refresh" content="4; url=http://www.truth-for-youth.com/">
<link rel="stylesheet" type="text/css"href="main.css" />
<body>
<table width="309" border="0" align="center">
  <tr>
    <td><div align="center" class="Title2">
Thank You <?php
echo "".$_POST['name']."";
?>
    </div>
      <p align="center" class="style1">Your message was sent successfully!</p>
      <p align="center" class="SmallText">If you are not automatically redirected in a few seconds, <a href="http://www.truth-foryouth.com/">click here</a> to proceed.</p>
    <p class="style4">&nbsp;</p></td>
  </tr>
</table>
</body>
</html>
How do I make it do both at the same time? In the thank you page it thanks the person by name, otherwise I would just make it go there after posting the message.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Contact form "thank you" page & post it?

Post by andym01480 »

If you make the mail call an "if" statement (it returns a 1 if successful) then you can have your thank you page either of these two ways

Code: Select all

if (mail(to,subject,message,header)) include("thankyou.php");

Code: Select all

<?php
  $name = $_POST['name'] ;
  $email = $_POST['email'] ;
  $message = $_POST['message'] ;
 
 
 if( mail( "akjackson1@gmail.com", "Contact Form", "Name: ". $name . "\r\n\r\n". "Email: " . $email . "\r\n\r\n" . "Message: ". $message . "\r\n\r\n". "Mailing List: ". $mailinglist, "From: $email" ))
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Message sent successfully</title>
<meta http-equiv="refresh" content="4; url=http://www.truth-for-youth.com/">
<link rel="stylesheet" type="text/css"href="main.css" />
<body>
<table width="309" border="0" align="center">
  <tr>
    <td><div align="center" class="Title2">
Thank You <?php
echo "".$_POST['name']."";
?>
    </div>
      <p align="center" class="style1">Your message was sent successfully!</p>
      <p align="center" class="SmallText">If you are not automatically redirected in a few seconds, <a href="http://www.truth-foryouth.com/">click here</a> to proceed.</p>
    <p class="style4">&nbsp;</p></td>
  </tr>
</table>
</body>
</html>
<?php
}
?>
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: Contact form "thank you" page & post it?

Post by akjackson1 »

Thanks, I tried a simple send mail script and it didn't work on the host, they must have something turned off??? Anyway, thanks for the script I will definably use it somewhere :)
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: Contact form "thank you" page & post it?

Post by akjackson1 »

What could be turned off on a host that makes this script not work? It works except I don't get the email, even with a simple script. Is there a way around it? I really need a send mail and thank you script on the host.

Please help.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Contact form "thank you" page & post it?

Post by andym01480 »

Some hosts are nervous about having mail(), because badly written scripts allow spammers to send millions of emails from a form. The secret of a good script that mails from a form is to make sure the email address is just an email address - Google for "email validation" but use a fairly new one as lots of people have written ones that don't allow .info etc!

3 solutions...
i) ask the host to switch mail() on for you - it's a setting in php.ini
ii) use Chris Corbyn's swiftmailer which if I remember right doesn't use mail() and incorporates some of the safety stuff above
iii) switch to a better host - better not advertise the one I use - cheap and very good customer service. pm if you want to know who!
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: Contact form "thank you" page & post it?

Post by akjackson1 »

Thanks andym01480, I have downloaded Chris's mailer, I will try it out soon.

I would like to know what host you use, has anybody had any experience with the payed version of 50webs? I have bean happy with the free one, but it has no server side language support.

Adam
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Contact form "thank you" page & post it?

Post by andym01480 »

I use http://www.jnlhost.com - they were recently taken over by http://www.iisnet-networks.com - pretty good.

You do get what you pay for!
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: Contact form "thank you" page & post it?

Post by akjackson1 »

Thanks :)
Post Reply