Jump to content

Can someone help me? (Noob)


exoduses

Recommended Posts

I am trying to create a site for college, and I need to set up a form that will send to an email address, so I created a PHP to sort that out, but the PHP isn't working. Can someone take a look at the code underneath and tell me what I've done wrong.

 

Thanks

 

Jay

 

<?php

 

/* subject and email variables */

 

$emailSubject =  'Crazy PHP Scripting!';

$webMaster = '[email protected]';

 

 

/* Gathering Data Variables */

 

$emailField = $_POST['email'];

$nameField = $_POST['name'];

$commentsField = $_POST['comments'];

 

 

$body = <<<EOD

<br><hr><br>

Email: $email <br>

Name: $name <br>

Comments: $comments <br>

EOD;

 

$headers = "From: $email\r\n";

$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster, $emailSubject, $body, $headers);

 

 

/* results rendered as HTML*/

 

$theResults = <<<EOD

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<link href="site.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<p>Congratulations! Your mail was sent!</p>

<p>click <a href="homepage.html">here</a> to return to the mainpage</p>

</body>

</html>

EOD;

echo "$theResults";

 

 

?>

<html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<link href="site.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

.style1 {color: #0066CC}

-->

</style>

</head>

 

<body>

<table width="100%" border="0">

  <tr>

    <th scope="col"><a href="homepage.html">Homepage</a></th>

    <th scope="col"><a href="WhatisNinjitsu.html">What Is Ninjitsu?</a></th>

    <th scope="col"><a href="WeaponsClothing.html">Weapons / Clothing</a></th>

    <th scope="col"><a href="Media.html">Media</a></th>

    <th scope="col"><a href="ContactUs.html">Contact Us</a></th>

  </tr>

</table>

<p> </p>

<form action="phptest.php" name="form1" id="form1">

  <table width="100%" border="0" cellspacing="0" cellpadding="6">

    <tr>

      <td bgcolor="#000000"><label for="email">

          <div align="right" class="style1">Email Address:</div>

        </label>

      </td>

      <td bgcolor="#000000"><div align="left">

        <input name="email" type="text" id="email" size="35" maxlength="100" />

      </div></td>

    </tr>

    <tr>

      <td bgcolor="#000000"><label for="name">

          <div align="right"><span class="style1">Name</span>:</div>

        </label>

      </td>

      <td bgcolor="#000000"><div align="left">

        <input name="name" type="text" id="name" size="35" maxlength="80" />

      </div></td>

    </tr>

    <tr>

      <td bgcolor="#000000"><label for="phone"> </label>

          <label for="label"></label>

          <div align="right">

            <label for="label"></label>

            <label for="label"><span class="style1">Comments</span>:</label>

        </div></td>

      <td bgcolor="#000000"><textarea name="comments" id="comments" cols="26" rows="5"></textarea></td>

    </tr>

    <tr>

      <td bgcolor="#000000"> </td>

      <td bgcolor="#000000"><p align="left">

        <label></label>

        <br />

      </p></td>

    </tr>

    <tr>

      <td bgcolor="#000000"><div align="right">

        <label for="clear"></label>

        <input type="reset" name="clear" id="clear" value="Reset Form" />

      </div></td>

      <td bgcolor="#000000"><div align="right">

        <label for="submit"></label>

        <div align="left">

          <input type="submit" name="Submit" id="submit" value="Send Email!" />

        </div>

      </div></td>

    </tr>

  </table>

</form>

<p> </p>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/120342-can-someone-help-me-noob/
Share on other sites

when you have variables inside heredoc. wrap curly braces around them. {$var}

 

Also, run some checks on the $_POST's to make sure that they are set( isset() ) and they are of the correct type. for example if you expect a number( is_numeric() ). Or if its a string check its a certain length( strlen() ).

look up those functions on php.net . the isset(), strlen() and is_numeric().

 

<?php
/* Gathering Data Variables */

// check the POSTed data
if(isset($_POST['email']) && isset($_POST['name']) isset($_POST['comments']) {
      $emailField = $_POST['email'];   
      $nameField = $_POST['name'];   
      $commentsField = $_POST['comments'];
}

// fix up the variables in the heredoc
$body = <<<EOD

Email: {$email}

Name:{$name}

Comments: {$comments}

EOD; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.