PHP contact form help

Hi guys,
I’m helping a friend who bought a html template off template Monster, and having a bit of trouble with the script that was supplied.
I keep getting the error:

Notice: Undefined index: name in /home/stretchl/public_html/krysa/contact.php on line 2 Notice: Undefined index: email in /home/stretchl/public_html/krysa/contact.php on line 3 Notice: Undefined index: message in /home/stretchl/public_html/krysa/contact.php on line 4

Im recieving emails with subject “”<> and no message.

the HTML:

<form action="contact.php" method="POST" id="form" class="contact-form"> <div class="container1"> <div class="h"> <input name=”name” type="text" value="Name:" class="png" onblur="if(this.value=='') this.value='Name:'" onfocus="if(this.value =='Name:' ) this.value=''" /></div> <div class="h"> <input name=”email” type="text" value="E-mail:" class="png" onblur="if(this.value=='') this.value='E-mail:'" onfocus="if(this.value =='E-mail:' ) this.value=''" /></div> <textarea name=”message” rows="40" cols="30" class="png" onblur="if(this.value=='') this.value='MESSAGE:'" onfocus="if(this.value =='MESSAGE:' ) this.value=''" >MESSAGE:</textarea> <div class="container"> <div class="fright"> <a href="#" class="link1" onclick="document.getElementById('form').reset()">clear</a> &nbsp; &nbsp;<a href="#" class="link1" onclick="document.getElementById('form').submit()">send</a> </div> </div> </div> </form>

And the PHP script:
[php]<?php
$field_name=$_POST[‘name’];
$field_email = $_POST[‘email’];
$field_message = $_POST[‘message’];

$mail_to = ‘[email protected]’;
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>

<?php } else { ?>
<script language="javascript" type="text/javascript">
	alert('Message failed. Please, send an email to [email protected]');
	window.location = 'contact.html';
</script>
<?php } ?>[/php]

any help would be appreciated

PHP info Dump:
PHP Version 5.3.3
Build Date Feb 2 2012 23:42:48
Configure Command ‘./configure’ ‘–build=x86_64-redhat-linux-gnu’ ‘–host=x86_64-redhat-linux-gnu’ ‘–target=x86_64-redhat-linux-gnu’ ‘–program-prefix=’ ‘–prefix=/usr’ ‘–exec-prefix=/usr’ ‘–bindir=/usr/bin’ ‘–sbindir=/usr/sbin’ ‘–sysconfdir=/etc’ ‘–datadir=/usr/share’ ‘–includedir=/usr/include’ ‘–libdir=/usr/lib64’ ‘–libexecdir=/usr/libexec’ ‘–localstatedir=/var’ ‘–sharedstatedir=/var/lib’ ‘–mandir=/usr/share/man’ ‘–infodir=/usr/share/info’ ‘–cache-file=…/config.cache’ ‘–with-libdir=lib64’ ‘–with-config-file-path=/etc’ ‘–with-config-file-scan-dir=/etc/php.d’ ‘–disable-debug’ ‘–with-pic’ ‘–disable-rpath’ ‘–without-pear’ ‘–with-bz2’ ‘–with-exec-dir=/usr/bin’ ‘–with-freetype-dir=/usr’ ‘–with-png-dir=/usr’ ‘–with-xpm-dir=/usr’ ‘–enable-gd-native-ttf’ ‘–without-gdbm’ ‘–with-gettext’ ‘–with-gmp’ ‘–with-iconv’ ‘–with-jpeg-dir=/usr’ ‘–with-openssl’ ‘–with-pcre-regex=/usr’ ‘–with-zlib’ ‘–with-layout=GNU’ ‘–enable-exif’ ‘–enable-ftp’ ‘–enable-magic-quotes’ ‘–enable-sockets’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–enable-sysvmsg’ ‘–with-kerberos’ ‘–enable-ucd-snmp-hack’ ‘–enable-shmop’ ‘–enable-calendar’ ‘–without-sqlite’ ‘–with-libxml-dir=/usr’ ‘–enable-xml’ ‘–with-system-tzdata’ ‘–enable-force-cgi-redirect’ ‘–enable-pcntl’ ‘–with-imap=shared’ ‘–with-imap-ssl’ ‘–enable-mbstring=shared’ ‘–enable-mbregex’ ‘–with-gd=shared’ ‘–enable-bcmath=shared’ ‘–enable-dba=shared’ ‘–with-db4=/usr’ ‘–with-xmlrpc=shared’ ‘–with-ldap=shared’ ‘–with-ldap-sasl’ ‘–with-mysql=shared,/usr’ ‘–with-mysqli=shared,/usr/lib64/mysql/mysql_config’ ‘–enable-dom=shared’ ‘–with-pgsql=shared’ ‘–enable-wddx=shared’ ‘–with-snmp=shared,/usr’ ‘–enable-soap=shared’ ‘–with-xsl=shared,/usr’ ‘–enable-xmlreader=shared’ ‘–enable-xmlwriter=shared’ ‘–with-curl=shared,/usr’ ‘–enable-fastcgi’ ‘–enable-pdo=shared’ ‘–with-pdo-odbc=shared,unixODBC,/usr’ ‘–with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config’ ‘–with-pdo-pgsql=shared,/usr’ ‘–with-pdo-sqlite=shared,/usr’ ‘–with-sqlite3=shared,/usr’ ‘–enable-json=shared’ ‘–enable-zip=shared’ ‘–without-readline’ ‘–with-libedit’ ‘–with-pspell=shared’ ‘–enable-phar=shared’ ‘–with-tidy=shared,/usr’ ‘–enable-sysvmsg=shared’ ‘–enable-sysvshm=shared’ ‘–enable-sysvsem=shared’ ‘–enable-posix=shared’ ‘–with-unixODBC=shared,/usr’ ‘–enable-fileinfo=shared’ ‘–enable-intl=shared’ ‘–with-icu-dir=/usr’ ‘–with-enchant=shared,/usr’ ‘–with-recode=shared,/usr’
Server API CGI/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc
Loaded Configuration File /etc/php.ini
Scan this dir for additional .ini files /etc/php.d
Additional .ini files parsed /etc/php.d/curl.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, /etc/php.d/gd.ini, /etc/php.d/imap.ini, /etc/php.d/intl.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/phar.ini, /etc/php.d/soap.ini, /etc/php.d/sqlite3.ini, /etc/php.d/wddx.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlrpc.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,NTS
PHP Extension Build API20090626,NTS
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support enabled
Registered PHP Streams https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filters zlib., bzip2., convert.iconv., string.rot13, string.toupper, string.tolower, string.strip_tags, convert., consumed, dechunk

undefined index is just telling you that its finding a variable that is essentially empty or null - in other words, not used. most public sites have error reporting turned off so you don’t see it. just make that variable into an if statement using if(isset()). or you can use ini_set() to turn off the error reporting, depending on what the variable does, you can also surpress it with @, like $gd = @get_info(). any error messages associated with that call won’t show up. I wouldn’t recommend it though until you’re sure everything works.

Thank you Richei
I did a google search and got that answer aswell. The problem is while I am receiving emails from the form none of the inputs are coming through. Im hoping someone can look at the code and tell me where it needs changing so it works.

Hi,

The issue is with the following lines:
<input name=”name” type=“text” value=“Name:”
<input name=”email” type=“text” value=“Name:”
<input name=”message” type=“text” value=“Name:”

If you carefully notice these lines,you will find that the double quotes that you used to define the name of the textboxes are different than the actual double quotes. (you are using ” but it should be " ).

please use the correct double quote and this will fix the issue. I have tested it :slight_smile:

that is:
<input name=“name”
<input name=“email”
<input name=“message”

A HUGE thank you Sajan!!

Its works! :smiley:

Check the values too, they’re all Name:. Unless thats intentional.

Sponsor our Newsletter | Privacy Policy | Terms of Service