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
https://forums.phpfreaks.com/topic/202262-forms-emails-receipts/
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('[email protected]', $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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.