SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with this simple form

    I have this form which I have uploaded here http://jeremyw.phpnet.us/ to test. For some reason I am getting back "Email has not been send successfully". Can someone tell me why the email is not being sent. Below are the codes for the form and php page.


    Code JavaScript:
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
     
    function validateForm() {
    						if(document.Enquiry.Name.value == "") {
    						alert("Please Enter The Value For name ");
     
    						return false;
    						}
    						if(document.Enquiry.Email.value == "") {
    						alert("Please Enter The Value For email ");
     
    						return false;
    						}
    						if(document.Enquiry.Phone.value == "") {
    						alert("Please Enter The Value For phone number");
     
    						return false;
    						}
     
    		return true;
    		}
     
     
    /* This script is Copyright (c) Paul McFedries and 
    Logophilia Limited ([url]http://www.mcfedries.com/)[/url].
    Permission is granted to use this script as long as 
    this Copyright notice remains in place.*/
     
    function CalculateTotal(frm) {
        var order_total = 0
     
        // Run through all the form fields
        for (var i=0; i < frm.elements.length; ++i) {
     
            // Get the current field
            form_field = frm.elements[i]
     
            // Get the field's name
            form_name = form_field.name
     
            // Is it a "product" field?
            if (form_name.substring(0,4) == "PROD") {
     
                // If so, extract the price from the name
                item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))
     
                // Get the quantity
                item_quantity = parseInt(form_field.value)
     
                // Update the order total
                if (item_quantity >= 0) {
                    order_total += item_quantity * item_price
                }
            }
        }
     
        // Display the total rounded to two decimal places
        frm.TOTAL.value = round_decimals(order_total, 2)
     
    }
     
    function round_decimals(original_number, decimals) {
        var result1 = original_number * Math.pow(10, decimals)
        var result2 = Math.round(result1)
        var result3 = result2 / Math.pow(10, decimals)
        return pad_with_zeros(result3, decimals)
    }
     
    function pad_with_zeros(rounded_value, decimal_places) {
     
        // Convert the number to a string
        var value_string = rounded_value.toString()
     
        // Locate the decimal point
        var decimal_location = value_string.indexOf(".")
     
        // Is there a decimal point?
        if (decimal_location == -1) {
     
            // If no, then all decimal places will be padded with 0s
            decimal_part_length = 0
     
            // If decimal_places is greater than zero, tack on a decimal point
            value_string += decimal_places > 0 ? "." : ""
        }
        else {
     
            // If yes, then only the extra decimal places will be padded with 0s
            decimal_part_length = value_string.length - decimal_location - 1
        }
     
        // Calculate the number of decimal places that need to be padded with 0s
        var pad_total = decimal_places - decimal_part_length
     
        if (pad_total > 0) {
     
            // Pad the string with 0s
            for (var counter = 1; counter <= pad_total; counter++) 
                value_string += "0"
            }
        return value_string
    }
     
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
     
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
     
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
     
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
     
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    //-->
    </script>
    <title>Enquiries</title>
    </head>
     
    <body MARGINHEIGHT="0" TOPMARGIN="0" bgcolor="#000000" onload="MM_preloadImages('Images/contact1.jpg','Images/machines.jpg','Images/enquiries.jpg','Images/ourproducts.jpg','Images/ourservice.jpg','Images/coffeeorder.jpg','Images/home.jpg')">
    <div align="center" height="100%"> 
      <table height="100%" border="0" cellspacing="0" id="layout" >
        <tbody>
          <tr> 
            <td width="200" id="tl">&nbspontact-us"> 
                </a><a href="httpcontact-us"> </a><a href="Contact.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image11','','Images/contact1.jpg',1)"><img src="Images/contact2.jpg" alt="Contact Us" name="Image11" width="80" height="13" border="0" id="Image11" /></a><a href="Machines.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image12','','Images/machines.jpg',1)"><img src="Images/machines2.jpg" alt="Machines" name="Image12" width="72" height="13" border="0" id="Image12" /></a><a href="Order.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image16','','Images/coffeeorder.jpg',1)"><img src="Images/coffeeorder2.jpg" alt="Coffee Order" name="Image16" width="91" height="13" border="0" id="Image16" /></a><a href="Enqiries.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image13','','Images/enquiries.jpg',1)"><img src="Images/enquiries2.jpg" alt="Enquires" name="Image13" width="69" height="13" border="0" id="Image13" /></a><a href="Products.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image14','','Images/ourproducts.jpg',1)"><img src="Images/ourproducts2.jpg" alt="Products" name="Image14" width="93" height="13" border="0" id="Image14" /></a><a href="OurService.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image15','','Images/ourservice.jpg',1)"><img src="Images/ourservice2.jpg" alt="Our Service" name="Image15" width="83" height="13" border="0" id="Image15" /></a><a href="Home.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image17','','Images/home.jpg',1)"><img src="Images/home2.jpg" alt="Home" name="Image17" width="50" height="13" border="0" id="Image17" /></a></div></td>
          </tr>
          <tr> 
            <td colspan="2" id="banner"><div id="headimg"><img src="Images/banner.jpg" width="981" height="126" /></div></td>
          </tr>
          <tr bgcolor="#000000"> 
            <td colspan="2" id="tagline"><img src="Images/special.jpg" width="399" height="30" />v</td>
          </tr>
          <tr bgcolor="#000000"> 
            <td id="sidebar"> <div align="center"><img src="Images/bean.jpg" width="200" height="300" align="baseline" /></div>
              <font color="#999999" size="-2" face="Arial">All content Copyright 
              2/font></td>
            <td bgcolor="#FFFFFF" id="content"> <div id="contentbox"> 
                <div style=" width:778px; height:395px; overflow:auto;">
                  <table width="759" height="360" border="0" align="center" cellpadding="6" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                    <tr> 
                      <td height="356"><font color="#333399" size="4"><em><strong><br />
                        </strong></em></font> <blockquote style="margin-right: 0px;" dir="ltr"> 
                          <div align="center">
                            <form action="contact_form_next.php" method="post" name="Enquiry" id="Enquiry" onsubmit="return validateForm()">
                              <div align="left"><br />
                                <table align="center" class="noprint">
                                  <tbody>
                                    <tr> 
                                      <td colspan="2"><font color="#FF0000" face="Arial">Fields 
                                        marked with * are mandatory.</font></td>
                                    </tr>
                                    <tr> 
                                      <td><font color="#000000" face="Arial">Name<font color="#FF0000">*</font></font></td>
                                      <td><input maxlength="100" size="50" name="Name" type="text" /></td>
                                    </tr>
                                    <tr> 
                                      <td><font color="#000000" face="Arial">Email<font color="#FF0000">*</font></font></td>
                                      <td><input maxlength="100" size="50" name="Email" type="text" /></td>
                                    </tr>
                                    <tr> 
                                      <td><font color="#000000" face="Arial">Company:</font><font color="#FFFFFF">:</font></td>
                                      <td><input maxlength="100" size="50" name="Company" type="text" /></td>
                                    </tr>
                                    <tr> 
                                      <td><font color="#000000" face="Arial">Address:</font></td>
                                      <td><input maxlength="100" size="50" name="Address" type="text" /></td>
                                    </tr>
                                    <tr> 
                                      <td><font color="#000000" face="Arial">Phone<font color="#FF0000">*</font></font></td>
                                      <td><input maxlength="100" size="50" name="Phone" type="text" /></td>
                                    </tr>
                                  </tbody>
                                </table>
                                <p align="center"> 
                                  <textarea rows="5" cols="45" name="Comments" id="Comments"></textarea>
                                  <br />
                                  <input name="Submit" value="Enquire" type="submit" />
                                </p>
                              </div>
                            </form>
                          </div>
                          <div align="center"></div>
                        </blockquote>
                        </td>
                    </tr>
                  </table>
                  <div align="center"></div>
                </div>
              </div>
              </td>
          </tr>
        </tbody>
      </table>
    </div>
    </body></html>

    PHP page.
    Code PHP:
    <?php 
    		$mail_recipient = "Jeremywoods@xtra.co.nz";
    		$mail_subject = "Enquiries";
    					$Name = Trim(stripslashes($_REQUEST['Name']));
    					$Email = Trim(stripslashes($_REQUEST['Email']));
    					$Company = Trim(stripslashes($_REQUEST['Company']));
    					$Address = Trim(stripslashes($_REQUEST['Address']));
    					$Phone = Trim(stripslashes($_REQUEST['Phone']));
    					$Comments = Trim(stripslashes($_REQUEST['Comments']));
    		$Body = "";
    					$Body .= $Name;
    					$Body .= $Email;
    					$Body .= $Company;
    					$Body .= $Address;
    					$Body .= $Phone;
    					$Body .= $Comments;
    									$headers .= 'MIME-Version: 1.0' . "\r\n";
    									$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     
    			// send email 
    $success = mail($mail_recipient, $mail_subject, $Body, $headers);
    	if($success==true) 
    	echo "Your mail has been Sent Successfully";
    	else
    	echo "Your mail has Not Sent Successfully";
     
    			?>
    Last edited by JeremyW; Aug 7, 2007 at 01:54.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Could it be missing curly brackets?
    PHP Code:
    if($success==true){
        echo 
    "Your mail has been Sent Successfully";

        }else{

        echo 
    "Your mail has Not Sent Successfully";


  3. #3
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think that is it because it did return a message. I tried a completley different script that I found and that did not work either so I am thinking that the problem might be with the free host that I have uploaded the files to.

  4. #4
    SitePoint Zealot
    Join Date
    May 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the even more simple script that would not work.

    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
     
    <body>
    <form method="post" action="FormToEmail.php">
    Email: <input name="email" type="text"><br>
    Message:<br>
    <textarea name="message" rows="15" cols="40"></textarea><br>
    <input type="submit">
    </form>
    </body>
    </html>

    Code PHP:
     <?php
    $to = "Jeremywoods@xtra.co.nz";
    $subject = "Contact Us";
    $email = $_REQUEST['email'] ;
    $message = $_REQUEST['message'] ;
    $headers = "From: $email";
    $sent = mail($to, $subject, $message, $headers) ;
    if($sent)
    {print "Your mail was sent successfully"; }
    else
    {print "We encountered an error sending your mail"; }
    ?>

  5. #5
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes most free host doesnot allow to send the mail...

    or limits it

    go to thier features ..
    actually mailserver requires resources so they dont allow sending mail..
    it would be better try a cheap paid host...

  6. #6
    SitePoint Addict operator's Avatar
    Join Date
    Aug 2004
    Location
    Bangkok
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to check with your host. Last week, my host began dis-allowing php mail. It is now necessary for me to use their phpFormMail solution. WHen they made this change, my php forms would behave exactly the same form the user perspective, but the messages no longer were received. Check with your host - it's probably the same thing.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •