Jump to content

Forms, Emails & Receipts


joe90

Recommended Posts

First post on PHP Freaks - hope you can help.

When visitors want to leave a comment on my site I've built a php script to have the contact form input into MySQL, however i now need to show the visitor a receipt page simply saying thanks and also email the website owner the visitors details.

Any help much appreciated.

Link to comment
Share on other sites

Check to see if the data has been inserted into the database and echo a thank you message, then send an e-mail using the mail() function.

 

E.g.

<?php
// MYSQL CONNECTION CODE

$email = trim($_POST['email']); // This is the users e-mail address
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);

if (isset($_POST['submit'])) {
  $sql = mysql_query(sprintf("INSERT INTO contact ( email, subject, message ) VALUES ( '%s', '%s', '%s' )", 
    mysql_real_escape_string($email),
    mysql_real_escape_string($subject),
    mysql_real_escape_string($message))
  );
  
  if ($sql) {
    echo 'Thank you for contacting us.';
    
    // Header information
    $from = 'From: '. $email ."\r\n" . 'Reply-To: '. $email;
    
    mail('admin@domain.com', $subject, $message, $headers);
  }
  else {
    echo 'Sorry your request could not be completed.';
  }
}
?>

 

That's very basic and it should be improved upon and secured properly with form validation.

 

Link to comment
Share on other sites

I'll give that coding a try but it's not just a 'Thank You' message I'm also looking for but for the site to display a php page with all the website navigation on, headers etc - or am i approaching this the wrong way?

Link to comment
Share on other sites

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.