PHP Contact form file

the mail() function

Moderators: macek, egami, gesf

freelancewebdesigner
New php-forum User
New php-forum User
Posts: 4
Joined: Wed Mar 09, 2011 9:11 am

PHP Contact form file

Postby freelancewebdesigner » Tue Jul 17, 2012 10:16 pm

I have devloped a contact form with PHP code. It work perfectly. when you submit the form all the information e-mail to you perfectly. After submitting the contact form it will take you back to you same contact page. Know want to make some changes in it. When some one submit the contact form a message appear "Thanks for contacting us we will reply you withing in 5 business days" and then return to you on contact page. I try to modify the code myself but can't able to do that.
PHP CODE:



Code: Select all

<?php
   
    if(!$_POST) exit;
   
    $email = $_POST['email'];
   
   
    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
       $error.="Invalid email address entered";
       $errors=1;
    }
    if($errors==1) echo $error;
    else{
       $values = array ('URL','email','Keyword','Title');
       $required = array('URL','email','Keyword','Title');
       
       $your_email = "info@bannistermarketinggroup.co.uk";   
       $email_subject = "Bannister Marketing Group: ".$_POST['subject'];
       $email_content = "Following is the keyword report:\n";
       
       foreach($values as $key => $value){
         if(in_array($value,$required)){
          if ($key != 'subject' && $key != 'company') {
            if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
          }
          $email_content .= $value.': '.$_POST[$value]."\n";
         }
       }
       
       if(@mail($your_email,$email_subject,$email_content)) {
          //echo 'thanks you we receive report witing 24hr';
          header("Location:http://bannistermarketinggroup.co.uk/site_optimization/");
            exit();
          
       } //else {
          //echo 'ERROR!';
       //}
    }
    ?>


**HTML CODE**



Code: Select all

<form action="contact.php" method="post">
                       <Div class="fieldbox">
                           <div class="textname">URL:</div>
                            <div class="field"><input type="text" id="URL" name="URL" /></div>
                            <div class="icon22"><img src="images/URLicon.jpg" /></div>
                        </Div>
                       
                        <Div class="fieldbox">
                           <div class="textname">Title:</div>
                            <div class="field"><input id="Title" type="text" name="Title" /></div>
                            <div class="icon22"><img src="images/titleicon.jpg" /></div>
                        </Div>
                       
                          <Div class="fieldbox">
                           <div class="textname">Keyword:</div>
                            <div class="field"><input id="Keyword" type="text" name="Keyword" />  </div>
                            <div class="icon22"><img src="images/keywordicon.jpg" /></div>
                        </Div>
                       
                        <Div class="fieldbox">
                           <div class="textname">E-mail:</div>
                            <div class="field"><input id="name" type="text" name="email" />  </div>
                            <div class="icon22"><img src="images/emailicon.jpg" /></div>
                        </Div>
                       
                        <div class="button">
                        <input type="image" type="text" src="images/submit.jpg" />   
                        </div>
                        </form>


Any once can help me please.Need to done it as soon as possible.

kyle04
New php-forum User
New php-forum User
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: PHP Contact form file

Postby kyle04 » Wed Jul 18, 2012 4:07 pm

Javascript is probably you best bet :

Code: Select all

if(@mail($your_email,$email_subject,$email_content)) {

echo "Thanks for contacting us we will reply you withing in 5 business days" ;

echo "script type=\"text/javascript\">";

echo "setTimeout(function(){window.location=\"http://bannistermarketinggroup.co.uk/site_optimization/\"},2000);";
echo "</script>";
}

The timeout figure 2000 can be altered (1000 = 1 second);
** add < before script type=, it keeps disappearing for some reason...
AndyP

freelancewebdesigner
New php-forum User
New php-forum User
Posts: 4
Joined: Wed Mar 09, 2011 9:11 am

Re: PHP Contact form file

Postby freelancewebdesigner » Mon Jul 23, 2012 10:36 pm

Thanks for your help. It works perfectly.

freelancewebdesigner
New php-forum User
New php-forum User
Posts: 4
Joined: Wed Mar 09, 2011 9:11 am

Re: PHP Contact form file

Postby freelancewebdesigner » Thu Jul 26, 2012 12:38 am

The form is working fine. Know After Submitting the form we want to send the some thank you message to user e-mail also. How can we do that in PHP code. Code is there in a post.

kyle04
New php-forum User
New php-forum User
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: PHP Contact form file

Postby kyle04 » Thu Jul 26, 2012 2:39 pm

if(@mail($your_email,$email_subject,$email_content)) {

$thank_you = "Thanks for contacting us we will reply you withing in 5 business days" ;
$subject = "bannistermarketinggroup form submission"; // or whatever

if(@mail($email,$subject,$thank_you)) { // $email is the clients mail , send the thank you message

echo "$thank_you;

echo "&lt;script type=\"text/javascript\">";

echo "setTimeout(function(){window.location=\"http://bannistermarketinggroup.co.uk/site_optimization/\"},2000);";
echo "</script>";
}
}


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest