Help with PHP Script

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
bloodlinek0
Forum Newbie
Posts: 6
Joined: Wed Oct 07, 2009 12:42 pm

Help with PHP Script

Post by bloodlinek0 »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi guys

I'm a newbie to php and hopefully some of you experienced guys will be able to spot what I'm doing wrong fairly quick....just please no making fun :P.
I'm just working on a simple script to automatically send an email from my contact form to a specific email address. For some reason I can't seem to get the script to work.

The PHP script (PS don't worry about the confirmation page I've just copied in any old html to show it works):

Code: Select all

<?php
 
/* Subject and Email Variables */
 
    $emailSubject = 'Crazy PHP Scripting!';
    $webMaster = 'dazan@treadeverywhere.com';
    
/*Gathering Data Varialbes */
    
    $forenameField = $_POST['forename'];
    $companyField = $_POST['company'];
    $positionField = $_POST['position'];
    $addressField = $_POST['address'];
    $cityField = $_POST['city'];
    $potscodeField = $_POST['postcode'];
    $telephoneField = $_POST['telephone'];
    $emailField = $_POST['email'];
    $businessmobilesField = $_POST['businessmobiles'];
    $blackberrysolutionsField = $_POST['blackberrysolutions'];
    $otherField = $_POST['other'];
    $timescaleField = $_POST['timescale'];
    
    $body = <<<EOD
<br><hr><br>
Name: $forename <br>
Company: $company <br>
Postion: $position <br>
Address: $address <br>
City: $city <br>
Postcode: $postcode <br>
Telephone: $telephone <br>
Email: $email <br>
Business Mobiles: $businessmobiles <br>
Blackberry Solutions: $blackberrysolutions <br>
Other: $other <br>
Timescale: $timescale <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>
 
         <meta name="description" content="" />
          <meta name="keywords" content="" />
           <meta name="author" content="Dazan Alyanai" />
            <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
 
            <title>Unsupported Browser</title>
 
                <link rel="shortcut icon" HREF="favicon.ICO">
 
 
               <style type="text/css">
                 <!--
 
        * {margin: 0; padding: 0}
 
        body {font-size: 62%;
        background-color: #666666;
        font: 1em Arial, Verdana; 
        color: #333333;
        }
 
        #wrapper {margin: 10em auto;
        padding-top: 0em;
        position: relative;
        padding: 1em;
        width: 400px;
        height: 200px;
        background-color: #999999;
 
        }
              --> 
               </style>
 
        </head>
         <body>
          <div id="wrapper">
            <h1>! Unsupported Browser !</h1>
             <br>
             <p>This Browser has known compatibility issues with modern web standards.<br><br>We recommend installing or updating to one of the following browsers.</p>
               <br>
                <a href="http://www.mozilla.com/en-US/products/download.html?product=firefox-3.5.3&os=osx&lang=en-US" style="float: right">Firefox</a><a href="http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx">IE 7+</a>
          </div>
 
         </body>
 
</html>
EOD;
echo "$theResults";
 
?>
The web page (html markup) is:

http://experiment.treadeverywhere.com/itmb/contact.html

Thanks in advance.

Regards


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Help with PHP Script

Post by pickle »

Welcome to the forums.

Please make sure to read the rules, specifically:
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
I've moved this thread to the appropriate forum.


To answer your problem - try taking out the $headers & see if that lets it work.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with PHP Script

Post by requinix »

bloodlinek0 wrote:For some reason I can't seem to get the script to work.
A description of what that meant would be nice. Error messages? Not seeing the email in your Inbox? Not seeing it at all?
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: Help with PHP Script

Post by desperado »

the $body and $theResults values should be wrapped in quotes.

e.g

$body = "..."
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with PHP Script

Post by requinix »

desperado wrote:the $body and $theResults values should be wrapped in quotes.
Not if you're using heredoc syntax, which OP is.
bloodlinek0
Forum Newbie
Posts: 6
Joined: Wed Oct 07, 2009 12:42 pm

Re: Help with PHP Script

Post by bloodlinek0 »

Hi guys sorry for the vague information and confusion about posting in the wrong place :s

removing the $header has worked thanks but what will display in the from email once it is received?
Also for my future reference how did you know it was the $header and what is wrong with it?

Also once I received my results, instead of receiving the information entered on the form it's displaying as blank but the <br> is displaying. so for example, ill get:

Name: <br>
Company <br>

and so on.

To answer the question before I removed the header and it wasn't working I meant that i click submit and the contactprocess.php page displays (blank) and no email received or confirmation message displayed.

I'm so close now but have been trying so hard I'm ready to give up! :(
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with PHP Script

Post by requinix »

Huh. Surprised I didn't see it before.

Code: Select all

$forenameField = $_POST['forename'];

Code: Select all

Name: $forename <br>
Using the wrong variables.

Code: Select all

$emailField = $_POST['email'];

Code: Select all

$headers = "From: $email\r\n"
(that line's missing a semicolon)
$headers is "From: \r\n" which is invalid, thus the email won't be sent.
bloodlinek0
Forum Newbie
Posts: 6
Joined: Wed Oct 07, 2009 12:42 pm

Re: Help with PHP Script

Post by bloodlinek0 »

Hi tasairis,

Thanks for your reply.

I've changed what you suggested and still no joy. I think maybe I've misunderstood what you are pointing out. Just to give you some insight, I'm not a programmer or developer and I don't even know what php stands for. So when you say variables etc means nothing to me, this is a small addition (so I thought) to a design I'm implementing.

Sorry but take me as a complete novice when explaining anything :)

Regards
bloodlinek0
Forum Newbie
Posts: 6
Joined: Wed Oct 07, 2009 12:42 pm

Re: Help with PHP Script

Post by bloodlinek0 »

Got it sorted.

I need to remove the

enctype="text/plain"

from the html.

Thanks for your help with the other things that were also causing issues guys.

Rdgs
Post Reply