SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Weridness with a php form + image

    trying to create a form to send a email with the option to attach a image.
    the form page is below and the action page below that - all i ever get is the error page " There was a problem sending your message, please try again later or call us 0207 421 5400."

    i turned on the captcha echo to see if that was failing but this is working fine. any help and a fresh pair of eyes would be most helpful and appreciated.


    Code:
    <html>
    <head>
    <title>Loveit | Contact us</title>
    <style type="text/css">
    	body {
    		font-family: Arial, "Trebuchet MS", Tahoma, sans-serif;
    		font-size: 11px;
    		line-height: 12px;	
    		color: #444444;
    	}
    	
    	a {
    		color: #FF0099;
    		font-weight: bold;
    		text-decoration: none;
    	}
    	
    	strong{
    		color: #FF0099;
    	}
    	
    	h1, h2, h3, h4, h5 {
    		color: #FF0099;
    	}
    	
    	.popup {
    		padding: 10px;
    	}
    	
    	table, tr, td {
    		font-family: Arial, "Trebuchet MS", Tahoma, sans-serif;
    		font-size: 11px;
    		line-height: 12px;
    		text-align: left;
    	}
    	
    	input, textarea {
    		font-size: 11px;
    		line-height: 14px;	
    		color: #444444;
    		background: #EEEEEE;
    		border: #BBBBBB 1px solid;
    	}
    	
    </style>
    </head>
    <body>
    <div class="popup">
      <h2>CONTACT US</h2>
      <table width="100%">
        <tr>
          <td><!--<strong>Celebrity gossip:</strong> Rebecca Davison<br />
            <strong>Email:</strong> <a class="readmore" href="mailto:rebecca&#46;davison&#64;burdamagazines&#46;co&#46;uk">CLICK HERE</a><br />
            <strong>Tel:</strong> 0207 421 5429 -->
            <strong>Beauty/Food:</strong> Elizabeth Doherty<br />
            <strong>Email:</strong> <a class="readmore" href="mailto:elizabeth&#46;doherty&#64;burdamagazines&#46;co&#46;uk">CLICK HERE</a><br />
            <strong>Tel:</strong> 0207 421 5438 </td>
          <td><strong>Real Life: </strong>Lauren Cumming<br />
            <strong>Email:</strong><a class="readmore" href="mailto:lauren&#46;cumming&#64;burdamagazines&#46;co&#46;uk"> CLICK HERE</a><br />
            <strong>Tel:</strong> 0207 421 5421 </td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td><p><strong>Senior Sales Executive:</strong> Clara Tobin<br />
              <strong>Email:</strong> <a class="readmore" href="mailto:clara&#64;peppublishing&#46;co&#46;uk">CLICK 
            HERE</a><br/>
            <strong>Tel:</strong> 020 7421 5419<br>
                    </p>
          <td><strong>Showbiz:</strong> Emma Pryer<br/>
            <strong>Email:</strong> <a href="mailto:emma.pryer&#64;loveitmagazine&#46;co&#46;uk">CLICK HERE</a><br/>
            <strong>Tel:</strong> 020 7421 5447 </td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td><!-- <br /><br/>  -->
            <strong>Classified Sales Executive:</strong> Ned Patten<br/>
            <strong>Email:</strong> <a class="readmore" href="mailto:ned&#64;peppublishing&#46;co&#46;uk">CLICK 
            HERE</a></td><br/>
            <td><strong>Fashion:</strong> Charlotte Bell<br />
            <strong>Email:</strong> <a class="readmore" href="mailto:charlotte&#46;bell&#64;burdamagazines&#46;co&#46;uk">CLICK HERE</a><br />
            <strong>Tel:</strong> 020 7421 54427<br>
            
            
        </tr>
        <tr>
          <td colspan="2" align="centre"><strong>Advertising Enquiries:</strong> 020 7421 5400 </td>
        </tr>
      </table>
      <br />
      Or please feel free to use the form below to contact us: <br />
      <table width="100%" border="0">
        <form enctype="multipart/form-data" method="post" action="comments_complete.php">
        
        <tr>
          <td width="15%">Full Name:</td>
        </tr>
        <tr>
          <td width="85%"><input  class="litext" type="text" name="name" size="35"></td>
        </tr>
        <tr>
          <td>Telephone:</td>
        </tr>
        <tr>
          <td><input  class="litext" type="text" name="tel" size="20"></td>
        </tr>
        <tr>
          <td><p>Email:</p>
          </td>
        </tr>
        <tr>
          <td><input  class="litext" type="text" name="email" size="40"></td>
        </tr>
        <tr>
          <td valign="top">Your message:</td>
        </tr>
        <tr>
          <td><textarea onFocus="this.value=''" name="comments" rows="8" cols="35">Enter your comments here...</textarea></td>
        </tr>
        <tr>
          <td valign="top">Attach a image:</td>
        </tr>
        <tr>
          <td> <fieldset> <input type="file" name="picture" id="picture" /></fieldset></td> 
        </tr>
        <tr>
          <td><input  class="litext" type="hidden" name="txt1" size="40" value=""></td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <?php
        	$randomnum=rand(1000,9000);
    	?>
        <form action='cont_sender.php?val=<?php echo $randomnum; ?>' method='post'>
          <tr>
            <td><img src='button1.php?number=<?php echo $randomnum; ?>'>
              <input type='hidden' name='val' value='<?php echo $randomnum; ?>'></td>
          </tr>
          <tr>
            <td><b>Please type the numbers above: </b></td>
          </tr>
          <tr>
            <td><input type='text' name='captcha' /></td> 
          </tr>
          <tr>
            <td colspan="2" align="center"><input type="submit" value="submit" /></td>
          </tr>
        </form>
      </table>
    </div>
    </div>
    </body>
    </html>

    Code:
    <style type="text/css">
    body {
    	font-family: Arial, "Trebuchet MS", Tahoma, sans-serif;
    	font-size: 11px;
    	line-height: 12px;
    	color: #444444;
    }
    a {
    	color: #FF0099;
    	font-weight: bold;
    	text-decoration: none;
    }
    strong {
    	color: #FF0099;
    }
    h1, h2, h3, h4, h5 {
    	color: #FF0099;
    }
    .popup {
    	padding: 10px;
    }
    table, tr, td {
    	font-family: Arial, "Trebuchet MS", Tahoma, sans-serif;
    	font-size: 11px;
    	line-height: 12px;
    	text-align: left;
    }
    input, textarea {
    	font-size: 11px;
    	line-height: 14px;
    	color: #444444;
    	background: #EEEEEE;
    	border: #BBBBBB 1px solid;
    }
    </style>
    <?php 
    $val=mysql_real_escape_string($_REQUEST['val']);
    $captcha=mysql_real_escape_string($_POST['captcha']);
    $code=mysql_real_escape_string($_REQUEST['code']);
    ?>
    <body style="padding:20px; background-color:#FFF; background-image:none;">
    <h2 style="color: #FF0099;">CONTACT US</h2>
    <?php
    
    // get posted data into local variables
    //$ip=$_SERVER['REMOTE_ADDR'];
    $EmailFrom = Trim(stripslashes($_POST['email'])); 
    $EmailTo = "james@peppublishing.co.uk";
    $Subject = "Love It! Website Enquiry";
    $Name = Trim(stripslashes($_POST['name'])); 
    $Tel = Trim(stripslashes($_POST['tel'])); 
    //$txt1= Trim(stripslashes($_POST['txt1']));
    $Comments = Trim(stripslashes($_POST['comments']));
    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (Trim($Name)=="") $validationOK=false;
    if (Trim($comments)!="") $validationOK=false;
    if ((string)$val!=(string)$captcha) $validationOK=false;
    echo"<br/><br/>$val is the value and $captcha is the captcha";
    
    
    if (!$validationOK) {
      print "<br/><br/>You have not filled in the required fields";
      exit;
    }
    
    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Telephone: ";
    $Body .= $Telephone;
    $Body .= "\n";
    $Body .= "Comments: ";
    $Body .= $Comments;
    $Body .= "\n";
    
    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: <$email>");
    
    // redirect to success page 
    if ($success){
     //<img style='margin-left:10px; margin-top:10px;' src='images/headers/comments_header.jpg' /> 
     echo "<br/> 
      <p style='padding:10px;'>
      Your message has been sent successfully!
      </p>
      
      ";
    }
    else{
      echo "
      <br/>
      <p style='padding:10px;'>
      There was a problem sending your message, please try again later or call us 0207 421 5400.
      
    
      </p>
      
      ";
    }
    
    
    ?>
    </body>
    </html>

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    While probably not hurting anything, for good practice, I'd change this:

    Code PHP:
     // redirect to success page  
    if ($success)

    to

    Code PHP:
     // redirect to success page  
    if ($success == true)

    and try removing the greater than and less than symbols. I belive you are also using the wrong variable in the headers argument.

    Code PHP:
    $success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

    In the future try to remove unnecessary code such as the HTML and CSS.
    Last edited by K. Wolfe; Oct 22, 2012 at 12:40. Reason: Updated variable name

  3. #3
    SitePoint Member
    Join Date
    Jul 2012
    Location
    Minnesota
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey James,

    One thing I noticed from your sending code is that it looks like your $email variable is never actually defined. Another thing that may give you some additional insight is to tail your outbound mail logs to see if that gives you any additional insight. Hope it helps.

  4. #4
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you enable PHP error_reporting and display_errors settings? If not, do that and see if the mail function throws an error. Post the error if there is one.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok made the updates k wolfe mentioned and enable the error reporting and the output is below

    Notice: Undefined index: code in /var/www/loveit/comments_complete.php on line 43
    CONTACT US

    Notice: Undefined variable: comments in /var/www/loveit/comments_complete.php on line 66

    7547 is the value and 7547 is the captcha Notice: Undefined variable: Telephone in /var/www/loveit/comments_complete.php on line 82
    There was a problem sending your message, please try again later or call us 0207 421 5400.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok having gone thought this multiply times with a fine tooth comb fixed the problems on the comment_complete.php so i get no errors from the php
    -commented out line 43
    - line 66 was capital C on one and c on the other
    - third and final was a typo "tel" + "telephone"
    ok after this and re uploading i no fill in my form and submitted i still get the error page

    "4221 is the value and 4221 is the captcha

    You have not filled in the required fields"

    <style type="text/css">
    body {
    font-family: Arial, "Trebuchet MS", Tahoma, sans-serif;
    font-size: 11px;
    line-height: 12px;
    color: #444444;
    }
    a {
    color: #FF0099;
    font-weight: bold;
    text-decoration: none;
    }
    strong {
    color: #FF0099;
    }
    h1, h2, h3, h4, h5 {
    color: #FF0099;
    }
    .popup {
    padding: 10px;
    }
    table, tr, td {
    font-family: Arial, "Trebuchet MS", Tahoma, sans-serif;
    font-size: 11px;
    line-height: 12px;
    text-align: left;
    }
    input, textarea {
    font-size: 11px;
    line-height: 14px;
    color: #444444;
    background: #EEEEEE;
    border: #BBBBBB 1px solid;
    }
    </style>
    <?php
    //error reporting
    ini_set('display_errors',1);
    error_reporting(E_ALL);

    $val=mysql_real_escape_string($_REQUEST['val']);
    $captcha=mysql_real_escape_string($_POST['captcha']);
    //$code=mysql_real_escape_string($_REQUEST['code']);
    ?>
    <body style="padding:20px; background-color:#FFF; background-image:none;">
    <h2 style="color: #FF0099;">CONTACT US</h2>
    <?php
    // Website Contact Form Generator
    // http://www.tele-pro.co.uk/scripts/contact_form/
    // This script is free to use as long as you
    // retain the credit link

    // get posted data into local variables
    //$ip=$_SERVER['REMOTE_ADDR'];
    $EmailFrom = Trim(stripslashes($_POST['email']));
    $EmailTo = "james@peppublishing.co.uk";
    $Subject = "Love It! Website Enquiry";
    $Name = Trim(stripslashes($_POST['name']));
    $Telephone = Trim(stripslashes($_POST['tel']));
    $txt1= Trim(stripslashes($_POST['txt1']));
    $comments = Trim(stripslashes($_POST['comments']));
    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (Trim($Name)=="") $validationOK=false;
    if (Trim($comments)!="") $validationOK=false;
    if ((string)$val!=(string)$captcha) $validationOK=false;
    echo"<br/><br/>$val is the value and $captcha is the captcha";


    if (!$validationOK) {
    print "<br/><br/>You have not filled in the required fields";
    exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Telephone: ";
    $Body .= $Telephone;
    $Body .= "\n";
    $Body .= "Comments: ";
    $Body .= $Comments;
    $Body .= "\n";

    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

    // redirect to success page
    if ($success == true){
    //<img style='margin-left:10px; margin-top:10px;' src='images/headers/comments_header.jpg' />
    echo "<br/>
    <p style='padding:10px;'>
    Your message has been sent successfully!
    </p>

    ";
    }
    else{
    echo "
    <br/>
    <p style='padding:10px;'>
    There was a problem sending your message, please try again later or call us 0207 421 5400.


    </p>

    ";
    }


    ?>
    </body>
    </html>

  7. #7
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) "You have not filled in the required fields" is a different error altogether and it is triggered by the line if (!$validationOK) which obviously means the user failed to enter some required fields. Debug the lines that modify the value of $validationOK and see which field was left empty.

    2) The mail function:

    Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

    PHP may or may not throw an error, warning or notice if the function fails. Depending on platform and the method PHP uses to send the email (IIS smtp on windows, sendmail on linux) you need to check the MTA (message transfer agent) configuration and/or MTA's error log. May be the MTA is not supposed to accept mails from localhost. Or may the settings in php.ini file under the SMTP section are wrong. Or may be the address had a typo. Change the line:

    PHP Code:
    mail($EmailTo$Subject$Body"From: $EmailFrom"); 
    to

    PHP Code:
    var_dump($EmailTo$Subject$Body"From: $EmailFrom");
    mail($EmailTo$Subject$Body"From: $EmailFrom"); 
    Also try adding angle brackets around all email addresses (I know at least one case where this fixed the issue):

    PHP Code:
    mail("<" $EmailTo ">"$Subject$Body"From: <" $EmailFrom ">"); 

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks coder the problem is all the fields including the image upload were filled in ( i filled the form myself) i have implemented your other suggestions to no avail.

  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone have any ideas?


Tags for this Thread

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
  •