Jump to content

PHP contact form not working for an app I'm writing.


TimKukulka
Go to solution Solved by jazzman1,

Recommended Posts

Hello, 

 

I am writing an app and I am trying to include a feedback form. I have the form and php script written but it isn't working. Can somebody take a look at it and see if I am missing something? This is my first try at writing PHP. 

 

The form will submit via email and have five sections: name, email, city, what and comments.

 

Submit to List


Name:



Email:


City:


What:



Comments:




 

 

The form shows up fine but it is the PHP I'm having trouble with. Below is the code I have so far for the HTML form and PHP file. I would like an email of the form to go to tim@akluk.com and another screen to pop up that says "Thank You" with a close button to take the viewer back to the home page. 

 

I appreciate any help I can get on getting this form to work. I am currently using Dreamweaver as my editor and I modified some code I found here: http://www.freecontactform.com/email_form.php. I am also referencing an O'Reilly book called Learning PHP, MySQL, JavaScript, & CSS. Thanks for your help! :)

 

submit.htmlsubmit.php

 

// Form HTML // "submit.html"

 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Submit to List</title>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="jquery.mobile-1.0.css" />
<link href="jQueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<link href="jQueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="jQueryAssets/jquery.ui.button.min.css" rel="stylesheet" type="text/css">
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="jquery.mobile-1.0.js"></script>
<script src="jQueryAssets/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jQueryAssets/jquery-ui-1.9.2.button.custom.min.js" type="text/javascript"></script>
</head>
 
<body>
 
<div data-role="dialog">
 
  <div data-role="header">
    <h1>Submit to List</h1>
  </div>
  
  <div data-role="content">
     <form action="submit.php" method="post" data-transition="none">
       <div data-role="fieldcontain">
         <label for="name">Name:</label>
         <input type="text" name="name" id="name" value="" required />
       </div>
 
       <div data-role="fieldcontain">
         <label for="email">Email:</label>
         <input type="email" name="email" id="email" value="" required />
       </div>
       <div data-role="fieldcontain">
         <label for="City">City:</label>
         <input type="text" name="city" id="city" value="" required />
       </div>
       <div data-role="fieldcontain">
         <label for="what">What:</label>
         <input type="text" name="what" id="what" value="" required />
       </div>
       
       <div data-role="fieldcontain">
         <label for="comments">Comments:</label>
         <textarea cols="40" rows="8" name="comments" id="comments"></textarea>
       </div>
   
  
       <input type="submit" value="Send" data-theme="a">
     
     </form>
  </div>
  
</div>
</body>
</html>
 
 
   //  PHP Code // "submit.php"
 
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Submission</title>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="jquery.mobile-1.0.css" />
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="jquery.mobile-1.0.js"></script>
</head>
 
<body>
 
<div data-role="dialog">
 
  <div data-role="header">
    <h1>Submit to List</h1>
  </div>
  
  <div data-role="content">
     
     <?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "tim@akluk.com";
 
    $email_subject = "List Suggestion";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['city']) ||
 
!isset($_POST['what']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $name = $_POST['name']; // required
 
$email_from = $_POST['email']; // required
 
$city = $_POST['city']; // required
 
    $what = $_POST['what']; // required
 
    $comments = $_POST['comments']; // required
 
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$name)) {
 
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$city)) {
 
    $error_message .= 'The City you entered does not appear to be valid.<br />';
 
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$what)) {
 
    $error_message .= 'What you entered does not appear to be valid.<br />';
 
  }
  
 
     if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
 
  }
 
 
 
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "Name: ".clean_string($name)."\n";
   
   $email_message .= "Email: ".clean_string($email_from)."\n";
   
    $email_message .= "City: ".clean_string($city)."\n";
 
  
 
    $email_message .= "What: ".clean_string($what)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
// create email headers
 
$headers = 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n".
 
'X-Mailer: PHP/' . phpversion();
 
@mail($email_to, $email_subject, $email_message, $headers);  
 
?>
     Thanks for your suggestion.
     
     <a data-role="button" data-inverse="true" href="index.html">Close</a>
     
  </div>
  
</div>
</body>
</html>
 
 
 

 

Link to comment
Share on other sites

I don't see anything that looks out of place.  I do note one thing that may keep it from working, and that is the FROM header in the mail function.  Reason being (and you will have to check with your host), is that many host will not accept mail to the SMTP server (to be sent), unless the FROM header is an email account residing on the SMTP server.

In these cases, I use an address from the site, and include a REPLY TO header with the senders address.

Of course, I would also suggest removing error suppression (@) from in front of the mail() function as well.

Link to comment
Share on other sites

Hello, 

 

Thank you for the quick response. I've added a domain specific address for the FROM header (tim@akluk.com as $email_to) and I took out the @ symbol before mail but I still seem to be getting errors (lots of script) in the app itself (and just "error" when I test from the server). Any ideas?

 

Attached is the new script if anybody has a moment to take a look at the script with the changes in red. 

 

Thank you for taking the time to look and help!

 

Tim

 

submit.htmlsubmit.php

 

// submit.php //

 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Submission</title>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="jquery.mobile-1.0.css" />
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="jquery.mobile-1.0.js"></script>
</head>
 
<body>
 
<div data-role="dialog">
 
  <div data-role="header">
    <h1>Submit to List</h1>
  </div>
  
  <div data-role="content">
     
     <?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "tim@akluk.com";
 
    $email_subject = "List Suggestion";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['city']) ||
 
!isset($_POST['what']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $name = $_POST['name']; // required
 
$email_from = $_POST['email']; // required
 
$city = $_POST['city']; // required
 
    $what = $_POST['what']; // required
 
    $comments = $_POST['comments']; // required
 
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$name)) {
 
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$city)) {
 
    $error_message .= 'The City you entered does not appear to be valid.<br />';
 
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$what)) {
 
    $error_message .= 'What you entered does not appear to be valid.<br />';
 
  }
  
 
     if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
 
  }
 
 
 
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "Name: ".clean_string($name)."\n";
   
   $email_message .= "Email: ".clean_string($email_from)."\n";
   
    $email_message .= "City: ".clean_string($city)."\n";
 
  
 
    $email_message .= "What: ".clean_string($what)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
// create email headers
 
$headers = 'From: '.$email_to."\r\n".
 
'Reply-To: '.$email_from."\r\n".
 
'X-Mailer: PHP/' . phpversion();
 
mail($email_to, $email_subject, $email_message, $headers);  
 
?>
     Thanks for your suggestion.
     
     <a data-role="button" data-inverse="true" href="index.html">Close</a>
     
  </div>
  
</div>
</body>
</html>
 
Link to comment
Share on other sites

Thanks, here is the error I'm getting:

 


"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What you entered does not appear to be valid.
'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion.
Link to comment
Share on other sites

Here is my code as of now: 

 

 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Submission</title>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="jquery.mobile-1.0.css" />
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="jquery.mobile-1.0.js"></script>
</head>
 
<body>
 
<div data-role="dialog">
 
  <div data-role="header">
    <h1>Submit to List</h1>
  </div>
  
  <div data-role="content">
     
     <?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "tim@akluk.com";
 
    $email_subject = "List Suggestion";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['city']) ||
 
!isset($_POST['what']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $name = $_POST['name']; // required
 
$email_from = $_POST['email']; // required
 
$city = $_POST['city']; // required
 
    $what = $_POST['what']; // required
 
    $comments = $_POST['comments']; // required
 
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$name)) {
 
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$city)) {
 
    $error_message .= 'The City you entered does not appear to be valid.<br />';
 
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$what)) {
 
    $error_message .= 'What you entered does not appear to be valid.<br />';
 
  }
  
 
     if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
 
  }
 
 
 
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "Name: ".clean_string($name)."\n";
   
   $email_message .= "Email: ".clean_string($email_from)."\n";
   
    $email_message .= "City: ".clean_string($city)."\n";
 
  
 
    $email_message .= "What: ".clean_string($what)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
// create email headers
 
$headers = 'From: '.$email_to."\r\n".
 
'Reply-To: '.$email_from."\r\n".
 
'X-Mailer: PHP/' . phpversion();
 
mail($email_to, $email_subject, $email_message, $headers);  
 
?>
     Thanks for your suggestion.
     
     <a data-role="button" data-inverse="true" href="index.html">Close</a>
     
  </div>
  
</div>
</body>
</html>
Link to comment
Share on other sites

Hi, thank you for replying to my post. The current PHP code is below. The error is posted above (the error I'm receiving in the actually app when it pulls the PHP). I don't see where I would be missing a quotation mark, I've highlighted the line that I think you are talking about. The form and php files are below as well. Thank you for troubleshooting my code in advance! 

 

submit.htmlsubmit.php

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Submission</title>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="jquery.mobile-1.0.css" />
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="jquery.mobile-1.0.js"></script>
</head>
 
<body>
 
<div data-role="dialog">
 
  <div data-role="header">
    <h1>Submit to List</h1>
  </div>
  
  <div data-role="content">
     
     <?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "tim@akluk.com";
 
    $email_subject = "List Suggestion";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['city']) ||
 
!isset($_POST['what']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $name = $_POST['name']; // required
 
$email_from = $_POST['email']; // required
 
$city = $_POST['city']; // required
 
    $what = $_POST['what']; // required
 
    $comments = $_POST['comments']; // required
 
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$name)) {
 
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$city)) {
 
    $error_message .= 'The City you entered does not appear to be valid.<br />';
 
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$what)) {
 
    $error_message .= 'What you entered does not appear to be valid.<br />';
 
  }
  
 
     if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
 
  }
 
 
 
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "Name: ".clean_string($name)."\n";
   
   $email_message .= "Email: ".clean_string($email_from)."\n";
   
    $email_message .= "City: ".clean_string($city)."\n";
 
  
 
    $email_message .= "What: ".clean_string($what)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
// create email headers
 
$headers = 'From: '.$email_to."\r\n".
 
'Reply-To: '.$email_from."\r\n".
 
'X-Mailer: PHP/' . phpversion();
 
mail($email_to, $email_subject, $email_message, $headers);  
 
?>
     Thanks for your suggestion.
     
     <a data-role="button" data-inverse="true" href="index.html">Close</a>
     
  </div>
  
</div>
</body>
</html>
 
Link to comment
Share on other sites

Paste the following on top of the file which contains all php(server side) logic. I think, it's named submit.php

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

PS: To be able to make some setting/editing in php config file named with crappy extension ".ini" you should have an admin(root) privilege to do this :) I'm not sure what environment are you using?

Edited by jazzman1
Link to comment
Share on other sites

Thank you for your reply. I am using Dreamweaver on a Macbook Air. I use Yahoo for my hosting and I have the app and PHP in a directory called "app". I have put the code you supplied into the submit.php file but I still receive an error in testing (I posted it at 12:19AM). Where would I find the config PHP file on my computer or on the server? Thanks for your assistance. 

 

 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Submission</title>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="jquery.mobile-1.0.css" />
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="jquery.mobile-1.0.js"></script>
</head>
 
<body>
 
<div data-role="dialog">
 
  <div data-role="header">
    <h1>Submit to List</h1>
  </div>
  
  <div data-role="content">
     
     <?php
 
 ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "tim@akluk.com";
 
    $email_subject = "List Suggestion";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['city']) ||
 
!isset($_POST['what']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $name = $_POST['name']; // required
 
$email_from = $_POST['email']; // required
 
$city = $_POST['city']; // required
 
    $what = $_POST['what']; // required
 
    $comments = $_POST['comments']; // required
 
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$name)) {
 
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$city)) {
 
    $error_message .= 'The City you entered does not appear to be valid.<br />';
 
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$what)) {
 
    $error_message .= 'What you entered does not appear to be valid.<br />';
 
  }
  
 
     if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
 
  }
 
 
 
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "Name: ".clean_string($name)."\n";
   
   $email_message .= "Email: ".clean_string($email_from)."\n";
   
    $email_message .= "City: ".clean_string($city)."\n";
 
  
 
    $email_message .= "What: ".clean_string($what)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
// create email headers
 
$headers = 'From: '.$email_to."\r\n".
 
'Reply-To: '.$email_from."\r\n".
 
'X-Mailer: PHP/' . phpversion();
 
mail($email_to, $email_subject, $email_message, $headers);  
 
?>
     Thanks for your suggestion.
     
     <a data-role="button" data-inverse="true" href="index.html">Close</a>
     
  </div>
  
</div>
</body>
</html>
Link to comment
Share on other sites

So just to clarify. You're using Dreamweaver as  a default code editor on your apple machine and you want to send emails through out your personal Yahoo account, right?

So, if it's true then you're able to make some changes into php config file because the server is located on your own machine and you're the owner.

So my further questions are, have you ever started the web (apache) server service and do you have a copy of php version installed on this machine?   

Edited by jazzman1
Link to comment
Share on other sites

Do you have php on your Mac? Are you doing this testing on your local machine or on Yahoo's server? When you said

 

Thanks, here is the error I'm getting:

I assumed that code was appearing in the browser. If that's not the case, you need to paste the code in post #11 in the top of your script, submit the form on a server, and paste what shows in the browser here. You can't fix errors if you don't know what they are.

Link to comment
Share on other sites

I am testing this on a server and the post was the error I was receiving when it pulled the script from the server on the compiled app (browser). Here it is again: 

 

 

"; echo $error."

"; echo "Please go back and fix these errors.

"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['city']) || !isset($_POST['what']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $city = $_POST['city']; // required $what = $_POST['what']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$city)) { $error_message .= 'The City you entered does not appear to be valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$what)) { $error_message .= 'What you entered does not appear to be valid.
'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "What: ".clean_string($what)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_to."\r\n". 'Reply-To: '.$email_from."\r\n". 'X-Mailer: PHP/' . phpversion(); mail($email_to, $email_subject, $email_message, $headers); ?> Thanks for your suggestion.
Link to comment
Share on other sites

I've never knew that Yahoo provides a web hiosting service, it's a something new to me.

So, do a simple test for us.

Open up Dreamweaver and connect to the yahoo server. Create a file named phpinfo.php inside this app directory (assuming it's a your web server working directory) and copy/paste the following simple php script: 

 

phpinfo.php

<?php

phpinfo();

Try to open this file up with your browser and tell us what result you're getting.

 

jazz.

Link to comment
Share on other sites

Thanks for your response I am currently away from my computer but when I get back I will definitely try it out and post the results. On a side note I have successfully created a mobile contact page in Adobe Muse and I have sent test messages from it on my Yahoo server. Now it is a matter of tieing the form into the app. It would just be different than the form I've been posting about.

Link to comment
Share on other sites

the "error messages" you get are part of the code on your page. My theory is that Dreamweaver is messing things up causing your code to be output to your browser instead of being executed. Can you try just uploading the script without dreamweaver and see if it works?

Link to comment
Share on other sites

  • Solution

Then, you have an actual syntax error. So, my IDE (NetBeans) complains of missing curly brace in submit.php file.

 

Take this instead yours ( see the line 176)

 

submit.php

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Submission</title>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="jquery.mobile-1.0.css" />
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="jquery.mobile-1.0.js"></script>
</head>

<body>

<div data-role="dialog">

  <div data-role="header">
    <h1>Submit to List</h1>
  </div>
  
  <div data-role="content">
     
 <?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "tim@akluk.com";
 
    $email_subject = "List Suggestion";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['city']) ||
	
		!isset($_POST['what']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $name = $_POST['name']; // required
	
	 $email_from = $_POST['email']; // required
	
	 $city = $_POST['city']; // required
 
    $what = $_POST['what']; // required
 
    $comments = $_POST['comments']; // required
 
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$name)) {
 
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$city)) {
 
    $error_message .= 'The City you entered does not appear to be valid.<br />';
 
 
 }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$what)) {
 
    $error_message .= 'What you entered does not appear to be valid.<br />';
	
  }
  
 
     if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
	
  }

 
 
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "Name: ".clean_string($name)."\n";
   
   $email_message .= "Email: ".clean_string($email_from)."\n";
   
    $email_message .= "City: ".clean_string($city)."\n";
 
  
 
    $email_message .= "What: ".clean_string($what)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
// create email headers
 
$headers = 'From: '.$email_to."\r\n".
 
'Reply-To: '.$email_from."\r\n".
 
'X-Mailer: PHP/' . phpversion();
 
mail($email_to, $email_subject, $email_message, $headers); 
 
} // missing closing curly brace
 
?>
     Thanks for your suggestion.
     
     <a data-role="button" data-inverse="true" href="index.html">Close</a>
     
  </div>
  
</div>
</body>
</html>

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.