Can anybody help me for the code below ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dinku33
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 4:43 pm

Can anybody help me for the code below ?

Post by dinku33 »

Code: Select all

 
Can anybody help me for the code below ?
 
I have html codes for Mailform as below. I want to make php code to support this html form. I have posted the php form but it is not proper. Can anybody help me ?
 
 
 
 
 

Code: Select all

<form action="feedback.php" method="post">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
<tr><td>Property name:</td><td><input type="text" name="propertyname" size="25" /></td></tr>
<tr><td>Number of rooms:</td><td><input type="text" name="numberofrooms" size="25" /></td></tr>
<tr><td>Star rating:</td><td><input type="text" name="starrating" size="25" /></td></tr>
<tr><td colspan="2">Address<br />
<textarea rows="15" cols="45" name="comments"></textarea></td></tr>
<tr><td>Phone number:</td><td><input type="text" name="phonenumber" size="25" /></td></tr>
<tr><td>Fax number:</td><td><input type="text" name="faxnumber" size="25" /></td></tr>
<tr><td>Email address:</td><td><input type="text" name="email" size="25" /></td></tr>
<tr><td>Website:</td><td><input type="text" name="website" size="25" /></td></tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Add your hotel" /><br />
</td>
</tr>
</table>
</form>
    

Code: Select all

<?php
/*
    CHFEEDBACK.PHP Feedback Form PHP Script Ver 2.08
    Generated by thesitewizard.com's Feedback Form Wizard.
    Copyright 2000-2007 by Christopher Heng. All rights reserved.
    thesitewizard and thefreecountry are trademarks of Christopher Heng.
 
    Get the latest version, free, from:
        http://www.thesitewizard.com/wizards/feedbackform.shtml
 
    You can read the Frequently Asked Questions (FAQ) at:
        http://www.thesitewizard.com/wizards/faq.shtml
    
    I can be contacted at:
        http://www.thesitewizard.com/feedback.php
    Note that I do not normally respond to questions that have
    already been answered in the FAQ, so *please* read the FAQ.
 
    LICENCE TERMS
    
    1. You may use this script on your website, with or
    without modifications, free of charge.
    
    2. You may NOT distribute or republish this script,
    whether modified or not. The script can only be
    distributed by the author, Christopher Heng.
    
    3. THE SCRIPT AND ITS DOCUMENTATION ARE PROVIDED
    "AS IS", WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE
    IMPLIED WARRANTY OF MECHANTABILITY OR FITNESS FOR A
    PARTICULAR PURPOSE. YOU AGREE TO BEAR ALL RISKS AND
    LIABILITIES ARISING FROM THE USE OF THE SCRIPT,
    ITS DOCUMENTATION AND THE INFORMATION PROVIDED BY THE
    SCRIPTS AND THE DOCUMENTATION.
 
    If you cannot agree to any of the above conditions, you
    may not use the script. 
    
    Although it is not required, I would be most grateful
    if you could also link to thesitewizard.com at:
 
       http://www.thesitewizard.com/
 
*/
 
// ------------- CONFIGURABLE SECTION ------------------------
 
// $mailto - set to the email address you want the form
// sent to, eg
//$mailto       = "youremailaddress@example.com" ;
 
$mailto = 'alpeshmpatel@gmail.com' ;
 
// $subject - set to the Subject line of the email, eg
//$subject  = "Feedback Form" ;
 
$subject = "Feedback Form" ;
 
// the pages to be displayed, eg
//$formurl      = "http://www.example.com/feedback.html" ;
//$errorurl     = "http://www.example.com/error.html" ;
//$thankyouurl  = "http://www.example.com/thankyou.html" ;
 
$formurl = "http://your-feed-back.htm" ;
$errorurl = "http://error.htm" ;
$thankyouurl = "http://thank-you.htm" ;
 
$uself = 1;
 
// -------------------- END OF CONFIGURABLE SECTION ---------------
 
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );
 
if (!isset($_POST['email'])) {
    header( "Location: $formurl" );
    exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
    header( "Location: $errorurl" );
    exit ;
}
 
if (get_magic_quotes_gpc()) {
    $comments = stripslashes( $comments );
}
 
$messageproper =
 
    "This message was sent from:\n" .
    "$http_referrer\n" .
    "------------------------------------------------------------\n" .
    "Name of sender: $name\n" .
    "Email of sender: $email\n" .
    "------------------------- COMMENTS -------------------------\n\n" .
    $comments .
    "\n\n------------------------------------------------------------\n" ;
 
mail($mailto, $subject, $messageproper,
    "From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;
 
?>
 
Last edited by dinku33 on Fri Jan 18, 2008 6:25 am, edited 2 times in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Can anybody help me for the code below ?

Post by Jonah Bron »

Do you receive errors, or does it just not send the feedback?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Can anybody help me for the code below ?

Post by Jonah Bron »

Do you receiver errors, or does it just not send the feedback?

Also, you can use the BBCode [syntax=php][/syntax] tags for your code, which color-codes your php. :wink:
dinku33
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 4:43 pm

Re: Can anybody help me for the code below ?

Post by dinku33 »

Hi my friend,

there is no bugging, and i have not checked. But i dont konw much about PHP coding. the thing which i know is HTML coding. I have made HTML code and want somebody to help me to write PHP code for me. Sorry it seems that i am so mean, but i would like to be clear.

Regards
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: Can anybody help me for the code below ?

Post by thinsoldier »

I'd say the "thesitewizard" stuff is problem #1. If you don't know php that big chunk of code is just going to mess with your mind.

rough non-working example of how I'd do this quickly

[form.php - the form page]

Code: Select all

 
<form action="feedback.php" method="post">
<input type="hidden" name="command' value="mailman" />
<!-- your form html goes here -->
</form>
 
 
 

[feedback.php - the page with php to process the form]

Code: Select all

 
<?
if($_POST['command'] == 'mailman') {
 
// get the php mailer class from 
// http://sourceforge.net/project/showfile ... p_id=26031
// http://phpmailer.codeworxtech.com/
include('class.phpmailer.php');
$mail = new PHPMailer;
        $mail->From = 'requestform@mysite.com';
        $mail->FromName = 'website form';
        $mail->AddAddress('myaddress@mysite.com');
        $mail->Subject = 'website form request';
        $mail->Body = print_r($_POST, true);
 
// If the mail gets sent successfully redirect the visitor to a "thanks for using my form" kind of page on your site.
        if($mail->Send()){ header("Location: thankyou.php"); } 
        //preprintr($mail);
}
?>
 
Warning: I have no idea what I'm talking about.
dinku33
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 4:43 pm

Re: Can anybody help me for the code below ?

Post by dinku33 »

Dear thinsoldier,

I am surprised that you did hard work for me to create entire new form.
Sorry to say that i am still in problem. as i dont know in which fields i should put my emil address etc.. and etc ...

last help ?

Thank you for your kind help

A Patel
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: Can anybody help me for the code below ?

Post by thinsoldier »

$mail->AddAddress('myaddress@mysite.com');

if the mail is going to you then your address goes there.
if you were sending mail to the person using the form then you'd use something like ($_POST['email']) to use the email address the visitor put in the form.



Also using Body = print_r($_POST, true) might not be the best formatted text. If you wanted to do a more custom formatted email then you'd need to use the various $_POST data from the form echoed into whatever text you want.

Code: Select all

<?
$bodywork = <<<heredoc_format
Mr./Ms. {$_POST['Firstname']} {$_POST['Lastname']} has sent you an email using your web form.
His/Her email address is: {$_POST['email']}
They requested {$_POST['this_many_rooms']} at a {$_POST['star_rating']} star hotel in the country of {$_POST['country']}
heredoc_format;
 
$mail->Body = $bodywork;
 
?>


But since this is just being sent to yourself it should be o.k. enough for you to read.
The email should arrive to you as plain-text(which makes the output of print_r easy to read). If it isn't plain text and everything is crammed onto 1 line then you need to add $mail->IsHTML(false); to set it to plain text.
Warning: I have no idea what I'm talking about.
Post Reply