4 Replies - 998 Views - Last Post: 16 March 2011 - 09:16 PM Rate Topic: -----

#1 ChrisDeCamp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-November 10

PHP Contact Form

Posted 14 March 2011 - 06:16 PM

Hello,

I have been trying to write PHP code to create a fully interactive Contact Form for my web site. I have been somewhat successful using different tutorials I have found on line. What I have put together allows the user to enter in their Name, Email, Telephone and Comments. The PHP form then generates a response to the user and Emails me their information. What I am trying to achieve is for the PHP form to generate a response that echos the users input such as "Hello 'User Name'! You have provided us a contact number of '123-456-7890' an email address of 'AnyEmailAddress@yahoo.com'." What I have succeeded in getting is the Email containing the users input sent to my Email address but the automated response to the user just has the tag "Hello" and does not include any of the user inputed info. Can someone please tell me how to correct this. I have looked this up on several tutorials but have not found the answer.

Thank you,

Chris DeCamp

Here is my PHP Code:

<?php
  
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $email = $_POST['email'];
  $telephone = $_POST['telephone'];
  $comments = $_POST['comments'];


    
 if (!isset($_POST['first_name'])) {


echo "Hello! $first_name";

 }
  elseif (empty($email) || empty($comments)) {
    header( "Location: http://www.ChrisDeCampProductions.com/error.html" );
  }
  else {

    
    mail( "ChrisDeCamp@ChrisDeCampProductions.com", "Contact Form Results", "$first_name $last_name\n$comments\n$telephone\n$email",  "From: $first_name,   < $email>" );
   
     header( "Location: http://www.ChrisDeCampProductions.com/phpscripts/sendmail.php" );


  }
?>


Is This A Good Question/Topic? 0
  • +

Replies To: PHP Contact Form

#2 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: PHP Contact Form

Posted 14 March 2011 - 07:58 PM

Well you use header where your mail function is, why not use an echo or print statement instead with a link instead of the header. You could also parae the vars through the header function,
Hope it helps.

Thanks,
Aaron1178
Was This Post Helpful? 1
  • +
  • -

#3 jonesa01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 125
  • Joined: 18-February 07

Re: PHP Contact Form

Posted 15 March 2011 - 10:22 AM

In general the php mail function is like this:

<?php
$to = "someone@somewhere.com";
$from = "noreply@somewhere.com";
$name = "Joe Bloggs";
$subject = "subject";
$message = "message here";
$header = "From: ".$name." <".$from.">";
if mail($to,$subject,$message,$header)){
echo "sent";
}else{
echo "error";
}



All that you need to do is to substitute the variables with the post data. However some hosts do not allow this.

View PostChrisDeCamp, on 14 March 2011 - 06:16 PM, said:

Hello,

I have been trying to write PHP code to create a fully interactive Contact Form for my web site. I have been somewhat successful using different tutorials I have found on line. What I have put together allows the user to enter in their Name, Email, Telephone and Comments. The PHP form then generates a response to the user and Emails me their information. What I am trying to achieve is for the PHP form to generate a response that echos the users input such as "Hello 'User Name'! You have provided us a contact number of '123-456-7890' an email address of 'AnyEmailAddress@yahoo.com'." What I have succeeded in getting is the Email containing the users input sent to my Email address but the automated response to the user just has the tag "Hello" and does not include any of the user inputed info. Can someone please tell me how to correct this. I have looked this up on several tutorials but have not found the answer.

Thank you,

Chris DeCamp

Here is my PHP Code:

<?php
  
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $email = $_POST['email'];
  $telephone = $_POST['telephone'];
  $comments = $_POST['comments'];


    
 if (!isset($_POST['first_name'])) {


echo "Hello! $first_name";

 }
  elseif (empty($email) || empty($comments)) {
    header( "Location: http://www.ChrisDeCampProductions.com/error.html" );
  }
  else {

    
    mail( "ChrisDeCamp@ChrisDeCampProductions.com", "Contact Form Results", "$first_name $last_name\n$comments\n$telephone\n$email",  "From: $first_name,   < $email>" );
   
     header( "Location: http://www.ChrisDeCampProductions.com/phpscripts/sendmail.php" );


  }
?>

Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: PHP Contact Form

Posted 15 March 2011 - 11:04 AM

View Postjonesa01, on 15 March 2011 - 01:22 PM, said:

In general the php mail function is like this:

<?php
$to = "someone@somewhere.com";
$from = "noreply@somewhere.com";
$name = "Joe Bloggs";
$subject = "subject";
$message = "message here";
$header = "From: ".$name." <".$from.">";
if mail($to,$subject,$message,$header)){
echo "sent";
}else{
echo "error";
}



All that you need to do is to substitute the variables with the post data. However some hosts do not allow this.


to elaborate on this...some email services Hotmail love to block anonymous mail or in some cases mails that say they come from some place yet it's ip address says different. using the domain name instead of say someguy@yahoo.com will in most cases prevent your email from being thrown in the virtual trash.

$from = "noreply@dreamincode.net"; //replace dreamincode.net with your domain name


suggested but optional
$header .= "Content-type: text/plain; charset=iso-8859-1";

This post has been edited by no2pencil: 15 March 2011 - 11:59 PM

Was This Post Helpful? 1
  • +
  • -

#5 ChrisDeCamp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-November 10

Re: PHP Contact Form

Posted 16 March 2011 - 09:16 PM

Hi Aaron1178,

Your tip really helped a lot!

Thank you,

Chris DeCamp





View Postaaron1178, on 14 March 2011 - 06:58 PM, said:

Well you use header where your mail function is, why not use an echo or print statement instead with a link instead of the header. You could also parae the vars through the header function,
Hope it helps.

Thanks,
Aaron1178


Hi Jonesa01!

Thank you for your help!

Chris DeCamp


View Postcodeprada, on 15 March 2011 - 10:04 AM, said:

View Postjonesa01, on 15 March 2011 - 01:22 PM, said:

In general the php mail function is like this:

<?php
$to = "someone@somewhere.com";
$from = "noreply@somewhere.com";
$name = "Joe Bloggs";
$subject = "subject";
$message = "message here";
$header = "From: ".$name." <".$from.">";
if mail($to,$subject,$message,$header)){
echo "sent";
}else{
echo "error";
}



All that you need to do is to substitute the variables with the post data. However some hosts do not allow this.


to elaborate on this...some email services Hotmail love to block anonymous mail or in some cases mails that say they come from some place yet it's ip address says different. using the domain name instead of say someguy@yahoo.com will in most cases prevent your email from being thrown in the virtual trash.

$from = "noreply@dreamincode.net"; //replace dreamincode.net with your domain name


suggested but optional
$header .= "Content-type: text/plain; charset=iso-8859-1";

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1