Forum Moderators: coopster
$subject = 'WANT SILVER NOW'; // Subject of email sent to you.
$emailadd = 'info@example.com'; // Your email address. This is where the form information will be sent.
$url = 'http://www.example.com/thank_you.html'; // Where to redirect after form is processed.
$req = '0'; // 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.
// --------------------------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.'">';
?>
</body>
</html>
The code on the contact page that is filled out on submit is:
<form name="form1" id="form1" method="post" action="scripts/simple_scripts1.php">
Are there other files that this script is dependant on that I have not addresses? Are there permission issues with different servers that may be blocking? the new site is on Godaddy.com
Please advise?
Thanks,
Jason
[edited by: dreamcatcher at 11:31 am (utc) on Jan. 24, 2009]
[edit reason] use example.com. Thanks. [/edit]
// Simple Form Script
// Copyright (C) 2005 Eric Zhang
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
//--------------------------Set these paramaters--------------------------
$subject = 'WANT SILVER NOW'; // Subject of email sent to you.
$emailadd = 'info@example.com'; // Your email address. This is where the form information will be sent.
$url = 'http://www.example.com/thank_you.html'; // Where to redirect after form is processed.
$req = '0'; // 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.
// --------------------------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;
---------------
Then here is the active code on the form:
<form name="form1" id="form1" method="post" action="scripts/simple_scripts1.php">
It is working on two of my other sites but this one is hosted at godaddy.com. I'm not sure what the problem is. I've tried to change the email address to a site on my server and it still doesn't work.
(not sure what meta refresh is?, I'm not a php writer I just knew what to do to get another site to work) Please be specific if possible and let me know if it could be server issue. godaddy.com said it wasn't. I'm completely stumped?
Jason
[edited by: eelixduppy at 6:05 pm (utc) on Jan. 26, 2009]
[edit reason] exemplified [/edit]
it just doesn't send the form info to email?
Although posed as a question, we will assume for now that this is the answer to my question, "what is not working?" ...
Monitor the mail() function for a TRUE/FALSE return value:
if (mail($emailadd, $subject, $text, 'From: '.$emailadd.'')) {
print "MAIL SENT SUCCESSFULLY";
exit;
} else {
print "MAIL FAILED MISERABLY";
exit;
} Next, try dumping the output to the browser right before sending the email. Dump out all your variables to see what values each contain and determine if anything looks incorrectly formatted.
If all looks well and there are no errors then let it go through again but this time send the form to an email account that you know will accept spam, etc. Your own test account that you can activate just for this purpose often works well here.
If the mail doesn't show up in that mailbox, then check your mail queue. If the mail is not in the mail queue, then your mail() function is failing and is likely returning a FALSE value as mentioned earlier.
Watch your logs throughout this process too. Logs are often the first to let you know where your issue lies.
If you want to help, you'll have to put it in a fool proof code style.
I really think you can overcome your issue here. The sample code above would be wrapped around your current/existing "mail" statement. The line where you actually perform the mail function. So, where your mail() function currently exists in your code today, comment that line out and replace it with the code above (making certain the mail statement is still the exact same as your original). What should happen is your browser should display one of the two messages, SUCCESS or FAILURE. It is your starting point for troubleshooting your issue.
<?php
// Simple Form Script
// Copyright (C) 2005 Eric Zhang
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/
//--------------------------Set these paramaters--------------------------
$subject = 'MORTGAGES-MI APPLICATION'; // Subject of email sent to you.
$emailadd = 'info@example.com'; // Your email address. This is where the form information will be sent.
$url = 'http://www.example.com/thank_you.html'; // Where to redirect after form is processed.
$req = '0'; // 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.
// --------------------------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.'')) { print "MAIL SENT SUCCESSFULLY"; exit; } else { print "MAIL FAILED MISERABLY"; exit; }
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
</body>
</html>
The browser window was completely blank.
Please advise?
[edited by: eelixduppy at 4:53 pm (utc) on Feb. 3, 2009]
[edit reason] exemplified [/edit]
} // <-- Here is the end of your foreach loop
// Here is the logic for testing your mail() function success:
if (mail($emailadd, $subject, $text, 'From: '.$emailadd.'')) {
print "MAIL SENT SUCCESSFULLY";
exit;
} else {
print "MAIL FAILED MISERABLY";
exit;
}
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
</body>
</html>
<?php
// Simple Form Script
// Copyright (C) 2005 Eric Zhang
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
//--------------------------Set these paramaters--------------------------
$subject = 'MORTGAGES-MI APPLICATION'; // Subject of email sent to you.
$emailadd = 'info@example.com'; // Your email address. This is where the form information will be sent.
$url = 'http://www.example.com/thank_you.html'; // Where to redirect after form is processed.
$req = '0'; // 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.
// --------------------------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;}
}
if (mail($emailadd, $subject, $text, 'From: '.$emailadd.'')) { print "MAIL SENT SUCCESSFULLY"; exit; } else { print "MAIL FAILED MISERABLY"; exit; }
$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.'">';
?>
</body>
</html>
-----------
It said mail failed miserabley. So I guess the mail function isn't working. What should I do contact the server in this case godaddy.com?
[edited by: eelixduppy at 5:28 am (utc) on Feb. 6, 2009]
[edit reason] exemplified [/edit]
BUT it is pretty much totally unsecured, used as is, is like calling for hell's gate to open, you need to first learning how to harden it.
Search for how securing phpmailer and you’ll figure what I mean.
I am not trying to belittle your endeavor, please understand that security has to be your number one concern.
Also you need to make sure that you are using the most recent release.
<edit>Typo</edit>
Coopster, let me know what to do next?
Jayrock its for [mysilverinfo.com...]
over
with no secure info for now
Jayrock, it's not about the info in the form, it's about the security of the PHP methods. Henry0 is saying this script can easily be abused to use your server to send spam, hack into your server, and who knows what else.
Take five minutes and look at this, it's by no means complete but succinctly describes the problem:
[w3schools.com...]