Jump to content
Larry Ullman's Book Forums

Recommended Posts

Larry,

 

I love your books, I have learned more from them than I did from actual classes... LOL  Thank you for taking the time to help us out when we run into problems.  I appreciate your knowledge. Please excuse my way of asking questions, as I am new and find it a bit difficult to make sense of it all.

 

I am new to PHP.  I can build static sites, but PHP syntax messes with me; even my HTML at times.. 

 

I am having a heck of a time figuring out why Chapter 11 : Script 11.1 will not function.  I have read many forums, searching out possible causes.  The script displays, will run, but nothing happens.  For instance when submitting, I can see the data populate the URL, but no "thank you" or "error" message appears. The script just hangs (URL never changes, appears to just hang at the below http in browser window bar).  

 

URL: (http://localhost/PHPandMySQLBook/ch3Site/email.php?

 

name=Me&email=some%40email.com&comments=TESTING+123+&submit=Send!)

 

The form resets ($_POST = array() ) is working.  I have also tried using your script and modifying the email address (using my own) to no avail. 

 

I have tested a very simple script locally that works fine.

 
$msg = "First line of text\nSecond line of text";
 
$msg = wordwrap($msg, 70);
 
mail("my@email.com", "My Subject", $msg);
 
When previewing the above simple script in my browser I receive the email (Mac Mail).
 
I have also attempted to use a remote copy of the script, to no avail.  In addition, I have tried MAMP pro to see if Postfix would help the script function: to no avail. I do not believe it is my 'send mail' method at this point.  In addition, I have tried changing the php.ini file to include my user/bin/my@email.com, but may not fully understand what it is I am truly doing.  
 
Furthermore, I have read appendix A, but it is difficult at best to follow with my newer version of PHP (PHP admin looks completely different).
 
I am a newbie obviously, and could use some help debugging the problem. Or some help in searching the web for a solution.  I do not understand 'postfix' or how it may affect my computer if settings are changed. 
 
I have stepped away several times to avoid over analyzing, I have rewritten the script, I have used the books script, I have uploaded to my ISP,  and tried locally.  Nothing seems to work except the above simple script.
 
My next line of thinking is to try an simplify the script adding one little piece at a time until it breaks?  You are correct Debugging has a serious learning curve..
 
Thank you in advance.
 
I am using:
DreamWeaver CS6 (in code mode, with Testing Server MAMP, and Remote via FTP all functional)
MAMP 3.0.5

PHP VERSION = 5.5.10

Mac OSX Mavericks 10.9.4

 

My current script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Contact Me</title>
</head>
 
<body>
<h1>Contact Me</h1>
<?php # Script 11.1 - email.php
# DO NOT RELY ON THIS SCRIPT AS HACKERS CAN AND WILL USE IT TO SPAM.  RATHER REFER TO FUTURE CHAPTER CHANGES.
 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!empty($_POST['name']) && !empty ($_POST['email']) && !empty ($_POST['comments']) ){
 
//Create the body
$body = "Name: {$_POST['name']}\n\n
Comments: {$_POST['comments']}";
 
//limit line lentgh 
$body = wordwrap($body, 70);
 
//Send the email
mail('my@email.com', 'Contact Form Submission', $body, "FROM: {_POST['email']}");  //This I change to
//my email which works for above simple mail() script.
 
//if it worked OK
echo '<p><em>Thank you for contactin me. I will reply some day.</em></p>';
 
//Clear the array
$_POST = array();
 
}else{ //Error message if it didn't work OK.
echo '<p style="font-weight: bold; color: #COO">Please fill out the form completely.</p>';
 
}
}
?>
 
<!--Begin the form-->
 
<p>Please fill out this form to contact me.</p>
 
<form action"email.php" method"post">
<p>Name: <input type="text" name="name" size="30" maxlength="60" vlaue="<?php if(isset($_POST['name']))
echo $_POST['name']; ?>" /></p>
    <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if(isset($_POST['email']))
echo $_POST['email']; ?>" /></p>
    <p>Comments:<textarea name="comments" rows="5" cols="30"><?php if(isset($_POST['comments'])) 
echo $_POST['comments']; ?> </textarea></p>
    <p><input type="submit" name="submit" value="Send!" /></p>
</form>
</body>
</html>

 

Link to comment
Share on other sites

Okay.. After several attempts to figure out the issue with this script the problem was basic syntax, and mail server postfix issue using MAMP 3.0.  

 

Specifically, my XHTML was missing the " = " for method = "post" within the form element.  After reviewing the debugging steps in chapter 8, and using other sources of information, the script is now functional.  

 

The issue with MAMP PRO; because the syntax problem within the XHTML the script simply did not execute.  I received no errors, and was not able to use 'echo' statements for debugging because the script never ran.  

 

I focused to hard on two problems at once with out slowing down and identifying that the XHTML syntax was correct.  I do not know how I missed that several times, but I did.  

 

Once the XHTML issue was found, the script functioned, which allowed me to properly input my domain extension into MAMP PRO 3.0 (yourdomain@com).

 

Lesson = step through each part of your code before identifying, or trying to solve another problem.  I was able to test my server and new something was wrong, but without my script working properly I was not able to fix the secondary issue (the postfix problem).

 

Hope this helps someone...

Link to comment
Share on other sites

 Share

×
×
  • Create New...