PDA

View Full Version : E-Mail Using PHP


pjdenter
04-24-2007, 03:49 PM
I'm attempting to use the tutorial "Using Dreamweaver and PHP to send form results to an email" to send results from 2 of my forms back to me: pjdenter@pjdenterprises.com. I don't understand how the 'confirmation.html' works. How do you set it up, etc. When I attempt to test my form, by hitting 'submit', the php file opens up.

Rich_A06
04-24-2007, 03:59 PM
Remember to name the form, that's where it can go wrong.

<form action="/your.php" method="post" enctype="multipart/form-data" name="form2">

pjdenter
04-29-2007, 02:34 PM
I'm still not having any success. I have everything set up as in the tutorial. When I click 'submit' on my form, the .php file opens. What am I doing wrong? My web site is www.pjdenterprises.com. Forms are 'Visitor's Log' and 'Submit Scores' under MNF Football.

davidj
04-29-2007, 03:01 PM
you cannot test this locally

you need a host that supports php and the mail() function

pjdenter
04-29-2007, 03:44 PM
I was testing it on the server at Polurnet.com.

davidj
04-29-2007, 03:46 PM
and that has php suport which you have access to

davidj
04-29-2007, 03:54 PM
to test your PHP access try the following

create a page and remove all html so its completly blank

add the following...

<?php phpinfo(); ?>

save this off and then upload this to your live server

then browse for this file through your browser

now tell me what results you get back

pjdenter
04-29-2007, 04:59 PM
Here's what I get:

PHP Version 5.2.0


System Linux invivo.nsglobalhost.net 2.6.9-42.0.3.ELsmp #1 SMP Mon Sep 25 17:28:02 EDT 2006 i686 Build Date Mar 11 2007 16:47:58 Configure Command './configure' '--prefix=/usr' '--with-xml' '--enable-bcmath' '--enable-calendar' '--with-curl' '--with-dom' '--with-dom-xslt' '--with-dom-exslt' '--enable-exif' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--with-gettext' '--with-imap=/usr/local/imap-2004g' '--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-mbregex' '--with-mcrypt' '--with-mhash' '--enable-magic-quotes' '--with-mysqli' '--with-mysql=/usr' '--with-openssl' '--enable-discard-path' '--with-pear' '--with-pspell' '--enable-sockets' '--enable-track-vars' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--with-zlib' Server API CGI Virtual Directory Support disabled Configuration File (php.ini) Path /usr/local/Zend/etc/php.ini PHP API 20041225 PHP Extension 20060613 Zend Extension 220060519 Debug Build no Thread Safety disabled Zend Memory Manager enabled IPv6 Support enabled Registered PHP Streams php, file, data, http, ftp, compress.zlib, https, ftps Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls Registered Stream Filters string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, convert.iconv.*, zlib.*
http://www.pjdenterprises.com/phpinfo.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 (http://www.zend.com/)

davidj
04-29-2007, 05:03 PM
that looks fine

post the php you have written

pjdenter
04-29-2007, 06:05 PM
Here's the .php file on the server. Thanks for your help. I'm really in over my head.

<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
&lt;?php<br />
//--------------------------Set these paramaters--------------------------<br />
<br />
// Subject of email sent to you.<br />
$subject = 'Visitor's Log'; <br />
<br />
// Your email address. This is where the form information will be sent. <br />
$emailadd = 'pjdenter@pjdenterprises.com'; <br />
<br />
// Where to redirect after form is processed. <br />
$url = 'http://www.pjdenterprises.com/visitor_confirm.html'; <br />
<br />
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.<br />
$req = '0'; <br />
<br />
// --------------------------Do not edit below this line--------------------------<br />
$text = &quot;Results from form:\n\n&quot;; <br />
$space = ' ';<br />
$line = '<br />
';<br />
foreach ($_POST as $key =&gt; $value)<br />
{<br />
if ($req == '1')<br />
{<br />
if ($value == '')<br />
{echo &quot;$key is empty&quot;;die;}<br />
}<br />
$j = strlen($key);<br />
if ($j &gt;= 20)<br />
{echo &quot;Name of form element $key cannot be longer than 20 characters&quot;;die;}<br />
$j = 20 - $j;<br />
for ($i = 1; $i &lt;= $j; $i++)<br />
{$space .= ' ';}<br />
$value = str_replace('\n', &quot;$line&quot;, $value);<br />
$conc = &quot;{$key}:$space{$value}$line&quot;;<br />
$text .= $conc;<br />
$space = ' ';<br />
}<br />
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');<br />
echo '&lt;META HTTP-EQUIV=Refresh CONTENT=&quot;0; URL='.$url.'&quot;&gt;';<br />
?&gt;
</body>
</html>

davidj
04-29-2007, 06:16 PM
whats happened is your code as been encoded into special HTML chars

you need to sort this out first

for example &lt;?php needs to be <?php

and...

$text = &quot;Results from form:\n\n&quot;; <br />

needs to be...

$text = "Results from form:\n\n" <br />

this is probably causing your script to fall over

pjdenter
04-29-2007, 06:20 PM
I'm sorry. This is what it looks like on the server:

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Visitor's Log';

// Your email address. This is where the form information will be sent.
$emailadd = 'pjdenter@pjdenterprises.com';

// Where to redirect after form is processed.
$url = 'http://www.pjdenterprises.com/visitor_confirm.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

davidj
04-29-2007, 07:34 PM
and the form code?

pjdenter
04-29-2007, 07:57 PM
Here's the form:


<!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"><!-- InstanceBegin template="/templates/temp4.dwt" codeOutsideHTMLIsLocked="false" -->
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Visitor's Log</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" href="emx_nav_left_2.css" type="text/css" />
<script type="text/javascript">
<!--
var time = 3000;
var numofitems = 7;
//menu constructor
function menu(allitems,thisitem,startstate){
callname= "gl"+thisitem;
divname="subglobal"+thisitem;
this.numberofmenuitems = allitems;
this.caller = document.getElementById(callname);
this.thediv = document.getElementById(divname);
this.thediv.style.visibility = startstate;
}
//menu methods
function ehandler(event,theobj){
for (var i=1; i<= theobj.numberofmenuitems; i++){
var shutdiv =eval( "menuitem"+i+".thediv");
shutdiv.style.visibility="hidden";
}
theobj.thediv.style.visibility="visible";
}

function closesubnav(event){
if ((event.clientY <4||(event.clientY > 107)){
for (var i=1; i<= numofitems; i++){
var shutdiv =eval('menuitem'+i+'.thediv');
shutdiv.style.visibility='hidden';
}
}
}
// -->
</script>
<style type="text/css">
<!--
.style2 { color: #005FA9;
font-weight: bold;
}
-->
</style>
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.style5 {
color: #005fa9;
font-size: 14px;
font-weight: bold;
}
-->
</style>
<!-- InstanceEndEditable -->
<meta name="Keywords" content="topps wings cards, topps wings, topps wings for sale, wings cigarette cards, 1950 royal baseball, 1951 bowman, 1952 bowman, 1952 topps" />
</head>
<body onmousemove="closesubnav(event);">
<div class="skipLinks">skip to:
<a href="#content">page content</a> |
<a href="#pageNav">links on this page</a> |
<a href="#globalNav">site navigation</a> |
<a href="#siteInfo">footer (site information)</a>
</div>
<div id="masthead">
<h1 id="siteName">PJD Enterprises</h1>
<div id="utility">
<a href="<A href="http://en.wikipedia.org/wiki/Main_Page">Wikipedia</a">http://en.wikipedia.org/wiki/Main_Page">Wikipedia</a> |
<a href="<A href="http://www.onelook.com">Dictionary</a">http://www.onelook.com">Dictionary</a> |
<a href="<A href="http://www.google.com/">Google</a">http://www.google.com/">Google</a> |
<a href="<A href="http://encarta.msn.com/">Encarta</a">http://encarta.msn.com/">Encarta</a> |
<a href="<A href="http://maps.google.com">Maps</a">http://maps.google.com">Maps</a> |
<a href="<A href="http://www.crh.noaa.gov/forecasts/NYZ065.php?warncounty=NYC027&city=Poughkeepsie">Weather</a">http://www.crh.noaa.gov/forecasts/NYZ065.php?warncounty=NYC027&city=Poughkeepsie">Weather</a> </div>
<div id="globalNav"> <img alt="" src="images/dwgifs/gblnav_left.gif" height="32" width="4" id="gnl" /> <img alt="" src="images/dwgifs/glbnav_right.gif" height="32" width="4" id="gnr" />
<div id="globalLink">
<a href="#" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">Topps Wings Cards</a>
<a href="#" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">Buffalo Nickels</a>
<a href="#" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">Oldies</a>
<a href="#" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">Photo Album</a>
<a href="#" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">Monday Night Football</a>
<a href="#" id="gl7" class="glink" onmouseover="ehandler(event,menuitem7);">Visitor's Log</a>
</div>
<!--end globalLinks-->
<form id="search" action="">
<input name="searchFor" type="text" size="10" />
<a href="">search</a>
</form>
</div>
<!-- end globalNav -->
<div id="subglobal1" class="subglobalNav">
<a href="<A href="http://www.sgccardregistry.com/">SGC">http://www.sgccardregistry.com/">SGC Card Registry</a> |
<a href="<A href="http://209.50.177.156/sgcweb/SignIn.aspx">SGC">http://209.50.177.156/sgcweb/SignIn.aspx">SGC Submission Status</a> |
<a href="<A href="http://www.psacard.com/set_registry/">PSA">http://www.psacard.com/set_registry/">PSA Card Registry</a> |
<a href="<A href="http://www.skytamer.com/index.html">Skytamer</a">http://www.skytamer.com/index.html">Skytamer</a>
</div>
<div id="subglobal2" class="subglobalNav">
<a href="<A href="http://www.pcgs.com/prices/frame.chtml?type=date&filename=buffalo_nickels">PCGS">http://www.pcgs.com/prices/frame.chtml?type=date&filename=buffalo_nickels">PCGS Price Guide</a> |
<a href="<A href="http://numismedia.com/fmv/prices/bufnkl/pricesgd.shtml">Numismedia">http://numismedia.com/fmv/prices/bufnkl/pricesgd.shtml">Numismedia Price Guide</a> |
<a href="<A href="http://www.greysheet.com/">the">http://www.greysheet.com/">the Greysheet</a>
</div>
<div id="subglobal3" class="subglobalNav">
<a href="#">Doo-Wop CDs</a> |
<a href="#">Oldies CDs</a> |
<a href="#">Oldies Quiz</a> |
<a href="#">Quiz Answers</a>
</div>
<div id="subglobal4" class="subglobalNav">
<a href="#">Nell & Pete</a> |
<a href="#">Peter & Beth</a> |
<a href="#">Anne</a> |
<a href="#">Other Photos</a>
</div>
<div id="subglobal5" class="subglobalNav">
<a href="#">Current Standings</a> |
<a href="#">Submit Scores</a>
</div>
<div id="subglobal6" class="subglobalNav">
<a href="#">subglobal6 link</a> |
<a href="#">subglobal6 link</a> |
<a href="#">subglobal6 link</a>
</div>
<div id="subglobal7" class="subglobalNav">
<a href="#">Sign Visitor's Log</a>
</div>
<div id="subglobal8" class="subglobalNav">
<a href="#">subglobal8 link</a> |
<a href="#">subglobal8 link</a> |
<a href="#">subglobal8 link</a> |
<a href="#">subglobal8 link</a> |
<a href="#">subglobal8 link</a> |
<a href="#">subglobal8 link</a> |
<a href="#">subglobal8 link</a>
</div>
</div>
<!-- end masthead -->
<div id="pagecell1">
<!--pagecell1-->
<img alt="" src="images/dwgifs/tl_curve_white.gif" height="6" width="6" id="tl" /> <img alt="" src="images/dwgifs/tr_curve_white.gif" height="6" width="6" id="tr" />
<div id="breadCrumb"><!-- InstanceBeginEditable name="breadcrumbs" --><a href="index.html">Home</a> / <a href="index.html">Up</a><!-- InstanceEndEditable --></div>
<div id="pageName"><!-- InstanceBeginEditable name="pagename" -->
<h2>Visitor's Log</h2>
<!-- InstanceEndEditable --></div>
<div id="content"><!-- InstanceBeginEditable name="update" -->
<form action="visitor_log.php" method="post" enctype="text/plain" name="Visitor's Log" id="Visitor's Log">
<div align="center"><span class="style5">Please provide the following information:</span> </div>
<br />
<table width="393" border="1" align="center" cellpadding="1" cellspacing="3" bordercolor="#666666" bgcolor="#e4e4e4">
<tr>
<th width="389" scope="col"><div align="center">
<label for="textfield">First Name</label>
<input name="First Name" type="text" id="textfield" accesskey="f" tabindex="1" size="20" />
</div></th>
</tr>
<tr>
<td><div align="center">
<label for="label">Last Name</label>
<input name="Last Name" type="text" id="label" accesskey="l" tabindex="2" size="30" />
</div></td>
</tr>
<tr>
<td><div align="center">
<label for="label2">e-Mail Address</label>
<input name="e-Mail" type="text" id="label2" accesskey="m" tabindex="3" size="30" />
</div></td>
</tr>
</table>
<div align="center"><br />
<span class="style5">How Do You Like My Web Site?</span> </div>
<br />
<table width="228" border="1" align="center" cellpadding="1" cellspacing="3" bordercolor="#666666" bgcolor="#e4e4e4">
<tr>
<td><label>
<input type="radio" name="Rating" value="Outstanding" />
Outstanding</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Rating" value="Not bad, but needs work" />
Not bad, but needs work</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Rating" value="Not my cup of tea" />
Not my cup of tea</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Rating" value="Get a life!" />
Get a life!</label></td>
</tr>
</table>
<div align="center"><br />
<span class="style5">Suggestions for added content or improvements, or just say hello:</span> </div>
<div align="center"><br />
<textarea name="Suggest" cols="50" rows="10" id="textarea" accesskey="s" tabindex="4"></textarea>
</div>
<label for="textarea"></label>
<div align="center"></div>
<div align="center"><br />
</div>
<table width="781" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><div align="center">
<input type="submit" class="style2" accesskey="s" tabindex="5" value="Submit" />
&nbsp;&nbsp;
<input name="reset" type="reset" class="style2" accesskey="r" tabindex="6" value="Reset Form" />
</div></td>
</tr>
</table>
</form>

<!-- InstanceEndEditable --></div>
<div id="siteInfo"> <img src="" width="44" height="22" />
<a href="site_map.html">Site Map</a> |
<a href="e_mail_obfuscate/txt-harq.htm">Webmaster</a> |
&copy;2006 PJD Enterprises </div>
</div>
<!--end pagecell1-->
<br />
<script type="text/javascript">
<!--
var menuitem1 = new menu(7,1,"hidden");
var menuitem2 = new menu(7,2,"hidden");
var menuitem3 = new menu(7,3,"hidden");
var menuitem4 = new menu(7,4,"hidden");
var menuitem5 = new menu(7,5,"hidden");
var menuitem6 = new menu(7,6,"hidden");
var menuitem7 = new menu(7,7,"hidden");
// -->
</script>
</body>
<!-- InstanceEnd --></html>

davidj
04-29-2007, 08:25 PM
the form is pointing to a page called visitor_log.php

is this the email script?