Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

contact form

the mail() function

Moderators: macek, egami, gesf

contact form

Postby itsrron » Wed May 02, 2012 5:04 am

Hey guys im only a front end developer that dabbles a bit in php when needed. For the life of me i cant seem to figure out what iv done wrong. I have created a website for a friend of mine and i copied a contact from i used from another website i created and copied the php file to send the for which worked on the previous website but it just wont work on this one :s.

the php is suposed to load a page saying thank you for your message and then redirect the page back to the home page.

is somebody would be so kind as to have a look and at least point me in the right direction it would be much appreciated.

the page in question is http://www.hardkase.co.uk/contact.html

thanks in advance guys

HTML code
Code: Select all
<div id="contactform">
<form action="contactform.php" method="post">
   <div class="row">
   <div class="label"><span>YOUR NAME *</span></div>
          <div class="input"><input type="text" id="name" class="contactdetail" name="name" value=""/>
   </div><!-- end input -->
   </div><!-- end row-->
                   
   <div class="row">
   <div class="label"><span>E-MAIL ADDRESS *</span></div>
   <div class="input">
            <input type="email" id="email" class="contactdetail" name="email" value=""/>
   </div><!-- end input -->
   </div><!-- end row-->
                   
   <div class="row">
   <div class="label"><span>YOUR MESSAGE *</span></div>
   <div class="input">
      <textarea id="message" name="message" class="mess"></textarea>
   </div><!-- end input -->
   </div><!-- end row-->
            
   <div class="submit">
   <input name="submit" type="submit" id="submit" onClick="MM_validateForm('fullname','','R','email','','RisEmail','message','','R');return document.MM_returnValue" value="Send"/>
  </div>
</form>
</div><!--ends form-->



PHP CODE: (dummy e-mail address)
Code: Select all
<?
   
/* Subject and Email Variables */

   $emailSubject = 'Contact Form';
   $webMaster = 'name@email.com';
   
   
   
/* Gathering Data Variables */

   $name = $_POST['name'];
   $email = $_POST['email'];
   $message = $_POST['message'];
   
   $body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Message: $message <br>
EOD;

   $headers = "From: $email\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($webMaster, $emailSubject, $body, $headers);
   
   
/* Results rendered as HTML */

   $theResults = <<<EOD
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Message Sent!</title>
<meta http-equiv="refresh" content="3;URL=http://www.hardkase.co.uk/">
<style type="text/css">
#text {   margin: auto; }
body { width: 100%;   height: 100%; background: black;}
h1, h2 {color: white;}
</style>
</head>

<div id="text"><h1>Thank you for your message.</h1>
<h2>Your request will be dealt with as soon as possible.</h2>
</div>
</body>
</html>
EOD;

?>
Last edited by itsrron on Wed May 02, 2012 5:30 am, edited 1 time in total.
User avatar
itsrron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sat Jan 07, 2012 12:04 pm
Location: London

Re: contact form

Postby Nullsig » Wed May 02, 2012 5:22 am

You should link the code for the PHP and HTML files so we can see what could be causing it.

Obviously you should remove sensitive information from the code and replace it with dummy information.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: contact form

Postby itsrron » Wed May 02, 2012 5:31 am

Nullsig wrote:You should link the code for the PHP and HTML files so we can see what could be causing it.

Obviously you should remove sensitive information from the code and replace it with dummy information.


very true, tis now added to the post :)
User avatar
itsrron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sat Jan 07, 2012 12:04 pm
Location: London

Re: contact form

Postby Nullsig » Wed May 02, 2012 6:29 am

Okay, the code looks legit. So what is the problem that is occurring?

Is the submission not being processed?

E-mail is not being received?
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: contact form

Postby itsrron » Wed May 02, 2012 6:42 am

the e-mail is coming though just fine, but the thank you message does not appear nor does it redirect back to the home page and i just cannot figure out why. I followed a tutorial to make the PHP file which gave me a sort of basic understand of php and the files does look like it should work.

the only thing im thinking of is that maybe the hosting somehow screws things up, the first time i used this file was on a godaddy hosting and that works (thank you message and redirect) but on this new one 123-reg it does not seem to work, i doubt thats in actual fact the issue but iv just run out of ideas now
User avatar
itsrron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sat Jan 07, 2012 12:04 pm
Location: London

Re: contact form

Postby Nullsig » Wed May 02, 2012 7:48 am

Its because you save the content that will notify the user and redirect them to a variable, but you never echo out that variable.

The last portion of your code should be:

Code: Select all
 $theResults = "
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Message Sent!</title>
<meta http-equiv="refresh" content="3;URL=http://www.hardkase.co.uk/">
<style type="text/css">
#text {   margin: auto; }
body { width: 100%;   height: 100%; background: black;}
h1, h2 {color: white;}
</style>
</head>

<div id="text"><h1>Thank you for your message.</h1>
<h2>Your request will be dealt with as soon as possible.</h2>
</div>
</body>
</html>";

echo  $theResults;
?>
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: contact form

Postby itsrron » Wed May 02, 2012 9:10 am

Nullsig i love you... it worked.

its been doing my head in so much recently, your help is much appreciated bro. Top man
User avatar
itsrron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sat Jan 07, 2012 12:04 pm
Location: London


Return to PHP coding => Mail

Who is online

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

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.