Link to home
Create AccountLog in
Avatar of imagekrazy
imagekrazy

asked on

Mail Form

My email form isn't working, I am testing on  the server and  I am getting  blank information  and no email of the information.
I am attaching the files, any help with it will be appreciated .
spineForm.php
contact.html
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Here is my working PHP Email demo.  Save as 'Email.php' so it can post to itself and set the $toText to your email address and try it.  It has worked on all web hosts that have SMTP server.
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');

# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Test Email Page";
    $announce="---";
}
else {
	if($fromText === "") die("No name!");
  $toText="youremail@yourdomain.com";
	$title="Test Email Page";
  $announce="Your Message has been Sent!";
	$header = "From: ".$fromText."\r\n";
//	$header .= "Cc: ".$ccText."\n";
	$header .= "Reply-To : ".$fromText."\r\n";
	$header .= "Return-Path : ".$fromText."\r\n";
	$header .= "X-Mailer: PHP\r\n";
	$header .= "MIME-Version: 1.0\r\n";
	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
//	ini_set(sendmail_from,$fromText);  
	mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
//	ini_restore(sendmail_from);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title)?></title>
<style type="text/css">
<!-- 
A:link { color: #999999; }
A:visited { color: #999999; }
A:hover {color: #0099ff;}
-->
</style>
<script type="text/javascript">
<!--
function check()
{
var at=document.getElementById("fromText").value.indexOf("@");
var eml=document.getElementById("fromText").value;
var nam=document.getElementById("nameText").value;
var alerttxt="";
var submitOK="true";

if (eml.length < 5 || at == -1)
    {
    alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
    submitOK="false"
    //return false;
    }
if (nam.length < 3)
    {
    alerttxt=alerttxt+"Please enter your name.\r\n";
    submitOK="false"
    //return false;
    }
if (submitOK=="false")
    {
    alert(alerttxt);
    return false;
    }

}
// -->
</script>
</head>

<body bgcolor="#ddeedd">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
<tr><td align="center">

<?php
if ($send != "") {
   	echo ("To: ".$toText."<br>\r\nSubject: ".$subjectText."<br>\r\n".$msgText."<br>\r\n".$header);
		}
?>

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<form method="POST" action="Email.php" onsubmit="return check();">
    <p><font size="3"><b>Name: <input type="text" name="nameText" id="nameText" size="46"></b></font></p>
    <p><font size="3"><b>Email: <input type="text" name="fromText" id="fromText" size="46"></b></font></p>
    <input type="hidden" name="subjectText" value="Web Mail">
    <p><font face="Arial" size="3"><b>Message Text:</b></font></p>
    <p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60"></textarea></b></font></p>
    <p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
    <input type="hidden" name="state" value="1">
  </form>
  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>

</font>
</td></tr>
</table> 
</div>

</body>
</html>

Open in new window

Avatar of imagekrazy
imagekrazy

ASKER

I appreciate your form, but I want to know my mistakes
steve
All the fields value you want to get on the server side MUST have their name attribute set
In your page, most of them only have an id attribute

Example you MUST have :
<input type="text" maxlength="30" id="email" name="email">
instead :
<input type="text" maxlength="30" id="email" >
Then run my working page to make sure things are working on your server and then we'll look at your code.

If you look at my code, you will see that the headers are much more complete than yours.  The first line in your header, $mailheaders="From my testing site\n"; , is not a valid header line.  Some SMTP servers will not send email without proper header info.
I set the $totext to my email but my email didn't receive it the message.
Did it show you the 'results' at the top of the page?  What web server and hosting company are you on?  What version of PHP?  Is there a SMTP server installed on your web server?
go daddy and yes on SMTP and latest version of php
and yes it stated this in the browser;
To: youremail@yourdomain.com
Subject: Web Mail
blah
From: circleimage@gmail.com Reply-To : circleimage@gmail.com Return-Path : circleimage@gmail.com X-Mailer: PHP MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1
More details please, I have this form and similar ones running on half a dozen web sites on Godaddy.  Linux? Windows?  PHP version?  Is the 'To' address a regular email address on your Godaddy hosting account or somewhere else?

PS: Email sent from a web page on Godaddy often takes a while to go out.  You often won't get it instantly.
Its something simple and I cant figure it out yet,
 On your form i replaced the $totext to my email address and it sits on my  server which is godaddy and it spits out what i showed you  which i will  show you below again; and its been  three hrs and no information in my godaddy email acct.

To: youremail@yourdomain.com
Subject: Web Mail
blah
From: circleimage@gmail.com Reply-To : circleimage@gmail.com Return-Path : circleimage@gmail.com X-Mailer: PHP MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1
Actually, I have been working with this for a while this afternoon.  My form works just about everywhere but it wasn't working this afternoon on my Godaddy Windows hosting account.  It turns out that the only way it would work is to send to an email address that is on my Godaddy account.  It would not send to an outside email address and even when it did work finally, it would not send to the 'Cc' address apparently.

That means the '$toText' must be a valid email on your Godaddy account.  At least that's the way it is working this afternoon.
Hello Dave, I appreciate the help.
I got my email form to show in the browser that i am testing, but Its not coming thru my godaddy email yet,  First my old form worked and I was trying to  fancy up the old form on another web page, and I found out that changing  certain things just screw up the way php was calling my information.
I never had a problem before with testing my form , now i have to figure out why it still hasn't come thru my  godaddy acct.
steve
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks Dave , I got mine to work with the  cool looking CSS style:) My information is catching in the browser, Firefox, IE.
The only situation is I have to call Godaddy and see why  the email isn't collecting on there side. And again thanks for the help, allowing me to  see your form been a big help, I wouldn't be able to fix mine if   I couldn't use your form.
steve
Glad to help, thanks for the points.