Form Help

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
beanboy3001
Forum Newbie
Posts: 10
Joined: Mon May 11, 2009 10:49 am

Form Help

Post by beanboy3001 »

I'm attempting to learn php. I thought I had a small grasp and then I did a tutorial on a form that mails you the information filled out in the form.
I built the html file, attached it to the php code, and tested it. It did not send the email but it did give me the text to say that I filled out the form. Which to me says that the code should be working since that is in the php file and not anywhere on the html file.

Any thoughts?

here is the code
and the place where it is stored online if you want to test the html.

http://www.razorbacksrealestate.com/con ... mpage.html

Code: Select all

 
<?php
 
/* Subject and Email Variables */
 
    $emailsubject = 'Crazy PHP Scripting!';
    $webMaster = 'jonathan@bdglr.com';
    
/* Gathering Data Variables */
 
    $emailField = $_POST['email'];
    $emailField = $_POST['name'];
    $emailField = $_POST['phone'];
    $emailField = $_POST['budget'];
    $emailField = $_POST['travelers'];
    $emailField = $_POST['comments'];
    $emailField = $_POST['newsletter'];
    
    $body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Phone Number: $phone <br>
Budget: $budget <br>
Number of Travelers: $travelers <br>
Comments: $comments <br>
Newsletter: $newsletter <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
<html>
<head>
<title>JakesWorks - travel made easy-Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
    background-color: #f1f1f1;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-style: normal;
    line-height: normal;
    font-weight: normal;
    color: #666666;
    text-decoration: none;
}
-->
</style>
</head>
 
<div>
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
 
?>
 
Last edited by Benjamin on Mon May 11, 2009 11:18 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
codex-m
Forum Newbie
Posts: 15
Joined: Sun May 10, 2009 8:08 am

Re: Form Help

Post by codex-m »

I think you have not define clearly your variables. For example:

Code: Select all

 
$emailField = $_POST['email'];
 
should be:

Code: Select all

 
$email = $_POST['email'];
 
or

Code: Select all

 
$emailField = $_POST['travelers'];
 
should be:

Code: Select all

 
$travelers = $_POST['travelers'];
 
beanboy3001
Forum Newbie
Posts: 10
Joined: Mon May 11, 2009 10:49 am

Re: Form Help

Post by beanboy3001 »

Thanks for the help. I changed that and it didn't seem to fix the problem. But that will help me clean up my coding so thank you for help. Any other thoughts on what it could be? I can't seem to put my finger on it but it seems like an issue with the command to mail the form.
User avatar
codex-m
Forum Newbie
Posts: 15
Joined: Sun May 10, 2009 8:08 am

Re: Form Help

Post by codex-m »

beanboy3001 wrote:Thanks for the help. I changed that and it didn't seem to fix the problem. But that will help me clean up my coding so thank you for help. Any other thoughts on what it could be? I can't seem to put my finger on it but it seems like an issue with the command to mail the form.
I think your server runs on Windows. Have you checked your PHP.ini? Read here for some reference: http://www.w3schools.com/PHP/php_ref_mail.asp. This might be a compatibility issue.
beanboy3001
Forum Newbie
Posts: 10
Joined: Mon May 11, 2009 10:49 am

Re: Form Help

Post by beanboy3001 »

If the issue is compatibility. Whats the best solution for that?
User avatar
codex-m
Forum Newbie
Posts: 15
Joined: Sun May 10, 2009 8:08 am

Re: Form Help

Post by codex-m »

beanboy3001 wrote:If the issue is compatibility. Whats the best solution for that?
PHP mail runs best on Apache Linux based servers, you are running Windows (which means a lot of things to do). If you cannot change your server type or having difficulty in dealing with it, contact your webhosting agency ask them to configure your mail settings.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: Form Help

Post by ldougherty »

If your site is indeed hosted on a Windows server then you'll need to adjust these lines in your php.ini

Code: Select all

 
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
 
; For Win32 only.
;sendmail_from = me@example.com
 
If you are not familiar with the settings your web host should be able to assist you.
beanboy3001
Forum Newbie
Posts: 10
Joined: Mon May 11, 2009 10:49 am

Re: Form Help

Post by beanboy3001 »

That seemed to fix the email issue.
The problem now is that the email I get has the catigories but none of the information that it is supposed to fill out.

Here is the code currently (The HTML is on http://www.razorbacksrealestate.com/con ... mpage.html)

Code: Select all

<?php
ini_set("SMTP","maila26.webcontrolcenter.com");
ini_set("smtp_port","8889");
ini_set("sendmail_from","razorback@razorbacksrealestate.com");
 
/* Subject and Email Variables */
 
    $emailsubject = 'Big Test';
    $webMaster = 'jonathan@bdglr.com';
    
/* Gathering Data Variables */
 
    $emailField = $_POST['email'];
    $nameField = $_POST['name'];
    $phoneField = $_POST['phone'];
    $budgetField = $_POST['budget'];
    $travelersField = $_POST['travelers'];
    $commentsField = $_POST['comments'];
    $newsletterField = $_POST['newsletter'];
    
    $body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Phone Number: $phone <br>
Budget: $budget <br>
Number of Travelers: $travelers <br>
Comments: $comments <br>
Newsletter: $newsletter <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
<html>
<head>
<title>JakesWorks - travel made easy-Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
    background-color: #f1f1f1;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-style: normal;
    line-height: normal;
    font-weight: normal;
    color: #666666;
    text-decoration: none;
}
-->
</style>
</head>
 
<div>
  <div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
 
?>
Last edited by Benjamin on Mon May 11, 2009 5:59 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply