Jump to content

php email contact form autoresponder help


ace2721

I need help with my script so it sends an automatic reply to there enquiry  

1 member has voted

  1. 1. I need help with my script so it sends an automatic reply to there enquiry

    • I need help with my script so it sends an automatic reply to there enquiry
      0
    • I need help with my script so it sends an automatic reply to there enquiry
      1


Recommended Posts

HI guys I hope someone can help, I have an enquiry form which send me an email and inserts into my database, what i am trying to do is add some code which also automatically sends them an email I am new to php so any help would be grately appreciated

 

this is the script

 

<?php

 

// Connect to database

$hostname = "1.1.1.1";

$username = "username";

$password = "password";

$dbname = "database";

$usertable = "table";

$f_name = $_REQUEST['f_name'];

$postcode = $_REQUEST['postcode'];

$tel = $_REQUEST['tel'];

$mobile = $_REQUEST['mobile'];

$email = $_REQUEST['email'];

$course = $_REQUEST['course'];

 

mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");

 

$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

 

$errmsg  = ''; // error message

$f_name  = ''; // sender's name

$postcode  = ''; // sender's name

$tel = ''; // message tel

$mobile = ''; // message tel

$email  = ''; // sender's email addres

$course = ''; // the message itself

 

if(isset($_POST['send']))

{

$f_name  = $_POST['f_name'];

$postcode  = $_POST['postcode'];

$tel = $_POST['tel'];

$mobile = $_POST['mobile'];

$email = $_POST['email'];

$course = $_POST['course'];

 

if(trim($f_name) == '')

{

$errmsg = 'Please enter your name';

}

else if(trim($postcode) == '')

{

$errmsg = 'Please enter your postcode';

}

else if(trim($tel) == '')

{

$errmsg = 'Please enter Your Telephone Number:';

}

else if(trim($mobile) == '')

{

$errmsg = 'Please enter your mobile';

}

else if(trim($email) == '')

{

$errmsg = 'Please enter your email address';

}

else if(!isEmail($email))

{

$errmsg = 'Your email address is not valid';

}

else if(trim($course) == '')

{

$errmsg = 'Please enter the course your interested in';

}

if($errmsg == '')

{

if(get_magic_quotes_gpc())

{

$tel = stripslashes($tel);

$message = stripslashes($message);

}

 

$query = "INSERT INTO table (id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('', '$f_name', '$postcode', '$tel', '$mobile', '$email' , '$course', NOW())";

 

$result = mysql_query($query) or DIE("Could not Execute Query on table $usertable");

 

 

 

// the email will be sent here

$to      = "emailme@domain.com";

 

$user_message .= "Name: $f_name \r\n";

        $user_message .= "postcode: $postcode \r\n";

        $user_message .= "tel: $tel \r\n";

        $user_message .= "mobile: $mobile \r\n";

        $user_message .= "email: $email \r\n";

        $user_message .= "course: $course \r\n";

        $headers = "- Enquiry \r\n";

        $headers .= "Reply-To: $email";

 

mail('emailme@domain.com','Enquiry',$user_message,$headers);

?>

<div align="center" class="boldenquire">Your message has been sent </div>

<?php

}

}

 

mysql_close();

 

if(!isset($_POST['send']) || $errmsg != '')

{

?>

<div align="center" class="ermsg"><?=$errmsg;?></div>

<form  method="post" name="msgform" id="msgform">

  <table border="0" align="center" cellpadding="2" cellspacing="1" class="maincell">

    <tr>

      <td align="center" colspan="2"><span class="boldenquire">        Please fill in your details <br />

        for more information.</span></td>

    </tr>

    <tr>

      <td>Your Name</td>

      <td><input name="f_name" type="text" class="eqform" value="<?=$f_name;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Nearest centre</td>

      <td><label>

        <select name="postcode" size="1" class="eqform" style="width:100px" value=" <?=$postcode;?>">

          <option value="centre">centre</option>

          <option value="centre">centre</option>

          <option value="centre">centre</option>

          <option value="centre">centre</option>

          <option value="centre">centre</option>

          <option value="centre">centre</option>

          <option value="centre">centre</option>

        </select>

      </label></td>

    </tr>

    <tr>

      <td>Tel </td>

      <td><input name="tel" type="text" class="eqform" value="<?=$tel;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Mobile</td>

      <td><input name="mobile" type="text" class="eqform" value="<?=$mobile;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Email </td>

      <td><input name="email" type="text" class="eqform" value="<?=$email;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Course of interest </td>

      <td><input name="course" type="text" class="eqform" value="<?=$course;?>" style="width:100px" />      </td>

    </tr>

    <tr align="center">

      <td colspan="2"><input name="send" type="submit" value="Send Message" onclick="return checkForm();" /></td>

    </tr>

    <tr align="left">

      <td colspan="2"><br />

          <script language="JavaScript">

var addr = '';

var host = '';

var email = '';

document.write(email);

</script></td>

    </tr>

  </table>

</form>

<?php

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.