Jump to content

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


Recommended Posts

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:

[code]<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>[/code]

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:

[code]<!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>[/code]

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
Huh, just send another email right after it:
Something like this:

[code]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 . '>');[/code]
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.
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?
[code]<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>[/code]

Try this...
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.