Schlo_50 Posted December 5, 2007 Share Posted December 5, 2007 Aside from validation which i will be adding later could someone point out the syntax errors etc with this mail script i have quickly put together. I just thought i'd try and get the concept right and then clean it up so it works. I am running it on a server and at the moment not even the 'echo' statement is doing anything. <?php if ($_POST[submit] == "Submit") { $siteowner = "dom@ahead4.com"; $name = $_POST['name']; $country = $_POST['country']; $company = $_POST['company']; $message = $_POST['message']; $emailfrom = $_POST['email']; $subject = "Executive Enquiry"; $messagebody = "From: $name Email: $emailfrom Country: $country Message: $message"; $headers = "From: $emailfrom"; mail($siteowner, $subject, $messagebody, $headers); echo "Your message has been sent, thank you."; } ?> Thanks people Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 Is your Form Submit Name using a capital S for Submit? If so, put single quotes around the word submit. Try if (isset ($_POST['submit'])) or if (isset ($_POST['Submit'])) No need to check if it == submit Quote Link to comment Share on other sites More sharing options...
boushley Posted December 5, 2007 Share Posted December 5, 2007 Well, for starters... its never getting inside your if statement... unless somewhere else you've declared Submit as a constant. Its should look like if($_POST['Submit']=="Submit") Also make sure that you have your capitalization correct (variable names are case sensitive). And if you'll check like this... if(isset($_POST['Submit'])) It won't throw a warning when its not set. Other than that it looks like the basic syntax is correct... although you may want to be wary when accepting data straight from the user without removing any malicious characters first. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 5, 2007 Author Share Posted December 5, 2007 Ok firstly, thanks for the replies guys! Secondly i have taken your advice and now my contact page looks like the following, although nothing is getting sent to my inbox/junk mail.: <?php if (isset ($_POST['submit'])) { $siteowner = "piper02089@hotmail.co.uk"; $name = $_POST['name']; $country = $_POST['country']; $company = $_POST['company']; $message = $_POST['message']; $emailfrom = $_POST['email']; $subject = "Executive Enquiry"; $messagebody = "From: $name Email: $emailfrom Country: $country Message: $message"; $headers = "From: $emailfrom"; mail($siteowner, $subject, $messagebody, $headers); echo "Your message has been sent, thank you."; } ?> <p class="title">Enquiries</p> <p class="main">Fields marked with a <span class="style1">*</span> are mandatory</p> <form action="<?php $_SERVER['php_self']; ?>" method="post"> <table width="377" border="0" cellpadding="5" cellspacing="0" class="main"> <tr> <td width="90" valign="top">Email:<span class="style1">*</span></td> <td width="267" valign="top"><label> <input type="text" name="email" id="email" /> </label></td> </tr> <tr> <td valign="top">Name:<span class="style1">*</span></td> <td valign="top"><label> <input type="text" name="name" id="name" /> </label></td> </tr> <tr> <td valign="top">Company:</td> <td valign="top"><label> <input type="text" name="company" id="company" /> </label></td> </tr> <tr> <td valign="top">Country:</td> <td valign="top"><select name="country" tabindex="12"> <option selected>Choose Country...</option> <option value="212">United Kingdom <option value="213">United States <option value="4">Afghanistan <option value="5">Albania <option value="6">Algeria <option value="7">American Samoa <option value="8">Andorra <option value="9">Angola <option value="10">Anguilla <option value="11">Antarctica <option value="12">Antigua And Barbuda <option value="13">Argentina <option value="14">Armenia <option value="15">Aruba <option value="16">Australia <option value="17">Austria <option value="18">Azerbaijan <option value="19">Bahamas <option value="20">Bahrain <option value="21">Bangladesh <option value="22">Barbados <option value="23">Belarus <option value="24">Belgium <option value="25">Belize <option value="26">Benin <option value="27">Bermuda <option value="28">Bhutan <option value="29">Bolivia <option value="30">Bosnia And Herzegowina <option value="31">Botswana <option value="33">Brazil <option value="34">Brunei Darussalam <option value="35">Bulgaria <option value="36">Burkina Faso <option value="37">Burundi <option value="38">Cambodia <option value="39">Cameroon <option value="3">Canada <option value="40">Cape Verde <option value="41">Cayman Islands <option value="42">Central African Republic <option value="43">Chad <option value="44">Chile <option value="45">China <option value="46">Christmas Island <option value="47">Cocos (Keeling) Islands <option value="48">Colombia <option value="49">Comoros <option value="50">Congo <option value="51">Cook Islands <option value="52">Costa Rica <option value="53">Cote D'Ivoire <option value="54">Croatia <option value="55">Cuba <option value="56">Cyprus <option value="57">Czech Republic <option value="58">Denmark <option value="59">Djibouti <option value="60">Dominica <option value="61">Dominican Republic <option value="63">Ecuador <option value="64">Egypt <option value="65">El Salvador <option value="67">Eritrea <option value="68">Estonia <option value="69">Ethiopia <option value="70">Falkland Islands <option value="71">Faroe Islands <option value="72">Fiji <option value="73">Finland <option value="74">France <option value="77">Gabon <option value="78">Gambia <option value="79">Georgia <option value="80">Germany <option value="81">Ghana <option value="82">Gibraltar <option value="83">Greece <option value="84">Greenland <option value="85">Grenada <option value="86">Guadeloupe <option value="87">Guam <option value="88">Guatemala <option value="89">Guinea <option value="90">Guinea-Bissau <option value="91">Guyana <option value="92">Haiti <option value="93">Honduras <option value="94">Hong Kong <option value="95">Hungary <option value="96">Iceland <option value="97">India <option value="98">Indonesia <option value="99">Iran <option value="100">Iraq <option value="101">Ireland <option value="102">Israel <option value="103">Italy <option value="104">Jamaica <option value="105">Japan <option value="106">Jordan <option value="107">Kazakhstan <option value="108">Kenya <option value="109">Kiribati <option value="110">Korea <option value="111">Kuwait <option value="112">Kyrgyzstan <option value="113">Latvia <option value="114">Lebanon <option value="115">Lesotho <option value="116">Liberia <option value="117">Liechtenstein <option value="118">Lithuania <option value="119">Luxembourg <option value="120">Macau <option value="121">Macedonia <option value="122">Madagascar <option value="123">Malawi <option value="124">Malaysia <option value="126">Mali <option value="127">Malta <option value="128">Marshall Islands <option value="129">Martinique <option value="130">Mauritania <option value="131">Mauritius <option value="132">Mayotte <option value="133">Mexico <option value="134">Moldova <option value="135">Monaco <option value="136">Mongolia <option value="137">Montserrat <option value="138">Morocco <option value="139">Mozambique <option value="140">Myanmar <option value="141">Namibia <option value="142">Nauru <option value="143">Nepal <option value="144">Netherlands <option value="145">Netherlands Antilles <option value="146">New Caledonia <option value="147">New Zealand <option value="148">Nicaragua <option value="149">Niger <option value="150">Nigeria <option value="151">Niue <option value="152">Norfolk Island <option value="153">Norway <option value="154">Oman <option value="155">Pakistan <option value="156">Palau <option value="157">Panama <option value="158">Papua New Guinea <option value="159">Paraguay <option value="160">Peru <option value="161">Philippines <option value="162">Pitcairn <option value="163">Poland <option value="164">Portugal <option value="165">Puerto Rico <option value="166">Qatar <option value="168">Romania <option value="169">Russian Federation <option value="170">Rwanda <option value="171">Saint Kitts And Nevis <option value="172">Saint Lucia <option value="173">Samoa <option value="174">San Marino <option value="175">Sao Tome And Principe <option value="176">Saudi Arabia <option value="177">Senegal <option value="178">Seychelles <option value="179">Sierra Leone <option value="180">Singapore <option value="181">Slovakia (Slovak Republic) <option value="182">Slovenia <option value="183">Solomon Islands <option value="184">Somalia <option value="185">South Africa <option value="186">Spain <option value="187">Sri Lanka <option value="190">Sudan <option value="191">Suriname <option value="192">Swaziland <option value="193">Sweden <option value="194">Switzerland <option value="195">Syrian Arab Republic <option value="196">Taiwan <option value="197">Tajikistan <option value="198">Tanzania <option value="199">Thailand <option value="200">Togo <option value="201">Tokelau <option value="202">Tonga <option value="203">Trinidad And Tobago <option value="204">Tunisia <option value="205">Turkey <option value="206">Turkmenistan <option value="207">United Kingdom <option value="208">United States <option value="209">Urugury <option value="210">Uzbekistan <option value="211">Vanuatu <option value="212">Venezuela <option value="213">Vietnam <option value="214">Virgin Islands <option value="215">Yemen <option value="216">Yugoslavia <option value="217">Zambia <option value="218">Zimbabwe </option> </select></td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> </td> </tr> <tr> <td colspan="2" valign="top"><label> <textarea name="message" id="message" cols="60" rows="10"></textarea> </label></td> </tr> <tr> <td valign="top"><label> <div align="right"> <input type="submit" name="submit" id="submit" value="Submit Enquiry" /> </div> </label></td> <td valign="top"><label> <input type="submit" name="Clear" id="Clear" value="Clear Form" /> </label></td> </tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 5, 2007 Share Posted December 5, 2007 if you have "Syntax errors" php will produce an error or warning so maybe it be helpful to tell us those. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 5, 2007 Author Share Posted December 5, 2007 There aren't any php errors being generated. I'll echo out the results to make sure everything is being posted. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 Try changing $messagebody = "From: $name Email: $emailfrom Country: $country Message: $message"; $headers = "From: $emailfrom"; to $messagebody = "Hi"; $headers = "From: me@me.com"; If that works, you need to change your code to remove your variables out from within the quotes and concantinate them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.