Jump to content

Contact form with automated content


nmrudolph

Recommended Posts

I'm working on a site that has close to a hundred employees, each with an email address. They want me to add a feature to where people can contact these employees, without actually knowing their email address. To do that, I made a new window that pops up when they click to email someone, and it asks the user for their name, email address, and a short message.

 

My problem is that the contact form is the same for every person. I don't know how to make that form direct to each individual person, without making each page by hand. (Something I don't want to do because there are so many and new employees being added all the time.)

 

Thanks in advance to all you who are much wiser than I. Please let me know if you need more info or source code.

Link to comment
Share on other sites

well i would say create a mysql table called "email_list"

 

create 4 fields named:

id

fname

lname

email

 

add all the emails and other info into the database

 

then create a script similar to this

 

we will call this page "email_someone.php"

<?php

//First you would need to connect to your mysql database ect...

if(isset($_POST['send_email_now'])) {

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$myemail = $_POST['myemail'];

$result = mysql_query("SELECT * FROM email_list
WHERE fname='$fname' AND lname='$lname'") or die(mysql_error()); 

$row = mysql_fetch_array( $result );

$email = $row['email'];

$to      = '$email';
$subject = '$subject';
$message = '$message';
$headers = 'From: $myemail' . "\r\n" .
    'Reply-To: $myemail' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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


} else {
?>
<form action="" method="post">
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
Subject: <input type="text" name="subject"><br>
Message:<br><textarea name="message"></textarea><br><br>

Your email: <input type="text" name="myemail"><br>

<input type="submit" name="send_email_now" value="Send">

<?php
}
?>


 

 

its pretty basic but it would work u would have to setup some of the stuff to for your own website though.

 

 

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.