Jump to content


Photo

Sending emails from forms (to both me and the person inputting information)


  • Please log in to reply
7 replies to this topic

#1 gibson

gibson
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 May 2006 - 09:03 PM

Hello, I am very new to PHP, in fact I really dont have a clue about the coding but I know I need to use it. I am building a website using Dreamweaver and want to have a form so a customer can contact me. The following is the HTML for the form I am using to play about with to try and get it working:

<form name="form1" method="post" action="submit.php">
  <label>Name
  <input name="name" type="text" id="name">
  </label>
  <p>
    <label>Email
    <input name="email" type="text" id="email">
    </label>
  </p>
  <p>
    <label>Message:<br>
    <textarea name="message" cols="50" rows="4" id="message"></textarea>
    </label>
  </p>
  <p>
    <center><label>
    <input type="submit" name="Submit" value="Submit">
    </label>
      <label>
     
    <input type="reset" name="Submit2" value="Reset">
    </label>
    </center>
  </p>
</form>

I found some PHP code on a website which allows me to send what is inputted in the form to my email address and this is it below:

<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p>
  <?php
$to="email removed for privacy reasons";
$subject="Mail from your website";
$from="FROM: ".$_POST['name']." <".$_POST['email'].">\n";
$message="This message is from the website.

Name: ".$_POST['name']."
Email: ".$_POST['email']."
Message: ".$_POST['message'];

//Now to actually send it
mail($to, $subject, $message, $from);
?> 
</p>
<p>Thank you for contacting us. We will get back to you within two business days.</p>
</body>
</html>

This code is working fine but it only sends me an email with what was inputted, I would also like the customer to be sent an email to tell them that I have received their query and will get back to them within two business days. Would you be able to tell me what code I would have to use for this? It would be going to the email that they have inputted and will be from my email with a subject of something like 'Thank you for contacting us' and then the message would be something like 'Thank you for contacting us. We will get back to you within two business days'

Thanks for any help you can give me

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 26 May 2006 - 10:30 PM

Huh, just send another email right after it:
Something like this:

mail($to, $subject, $message, $from);

$msg2 = 'Your Thank you message';
$email = 'YourEmail@example.com';
$name = 'Your Name';

mail($_POST['email'], 'Thank you', $msg2, 'From: ' . $name . '<' . $email . '>');

~ D Kuang

#3 gibson

gibson
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 May 2006 - 10:51 PM

Thank you, Ill try this out and Ill get back to you about whether it has worked. I tried something similar before but it was coming up an error but maybe I was just making a mistake in the syntax or something, so Ill try this code and hopefully itll work for me.

#4 gibson

gibson
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 May 2006 - 12:07 PM

Well this hasnt worked. I didnt receive any emails at all this time, not even the email with the information from the form which was the part that was working. It loads the page whenever I click the submit button without any problems so it looks as if it has worked, but I never got any emails. I have played about with the code and still it hasnt worked. Have you got any ideas of what could be wrong with it?

#5 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 27 May 2006 - 12:36 PM

<HTML>
    <head>
        <title>E-mail sent to your Inbox</title>
    </head>
    <body>
        <?php
            $to = "email removed for privacy reasons";
            $subject = "Mail from your website";
            $from = "FROM: ".$_POST['name']." <".$_POST['email'].">\n";
            $message = wordwrap("This message is from the website.\n\nName: ".$_POST['name']."\nEmail: ".$_POST['email']."\nMessage: ".$_POST['message'], 70);
            mail($to, $subject, $message, $from);
            $to = $_POST['email'];
            $subject = "Thankyou!";
            $from = "FROM: Site Admin <bob@hotmail.com>";
            $message = wordwrap("Thankyou ".$_POST['name'].", blah blah blah", 70);
            mail($to, $subject, $message, $from);
        ?>
        <p>Thank you for contacting us. Please check your Inbox.</p>
    </body>
</HTML>

Try this...

#6 gibson

gibson
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 May 2006 - 12:56 PM

This now comes up when you click the submit button:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected T_VARIABLE in /web/sites/320/gerrygibson/www.gerrygibson.f2s.com/submit2.php on line 15[/quote]

#7 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 27 May 2006 - 01:13 PM

Oh yeah, i had missed out a semicolon, i have edited the script so it should work now...

#8 gibson

gibson
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 May 2006 - 01:29 PM

ok, thanks very much, Ill try it out now

No error came up this time, now Ill just have to wait and see if the emails arrive. Ill reply later to tell you if its worked or not. Thanks again for your help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users