Dynaverse.net
Off Topic => Engineering => Topic started by: SkyFlyer on May 11, 2005, 01:42:30 am
-
Ok. I basically wrote a PHP script to send form data to an email address. (It was a shell, so a bit of it was there... a small bit).
I have it so it will send the data to one email address, but not two. (or more). Help anyone?
Help toasty? :P
-
php is Bonk's baliwick, not mine.
Jerry
-
Been ages since I used the mail functions... *nix or Windows server? (ie direct call to *nix sendmail vs use of php's mail functions...)
Last time I used mail in php I borrowed code from phpbb's account activation code as I recall...
Try here for info:
http://www.php.net/manual/en/ref.mail.php
http://www.php.net/manual/en/ref.imap.php
http://www.hotscripts.com/PHP/Scripts_and_Programs/Email_Systems/
Perhaps your troubles might be how you are retrieving the variables posted by the form? (i.e. in php5 use $_POST['variablename'] if the POST method was used by the form... (where 'variablename' corresponds to the name of the form input field that data is desired from)
here's a little script I started playing with while bored the other day - no mail functions - but may help you with forms submission and posted variables... the script posts to itself...
<?php
echo ("<html>");
echo ("<head>");
echo ("<title>The Oracle</title>");
echo ("</head>");
echo ("<body>");
echo ("<h1>Thinker</h1>");
echo ("<hr><br><br>");
echo ("<form method=POST action=");
echo $_SERVER['PHP_SELF'];
echo (">");
echo ("Enter a question for the oracle:<br><br>");
echo ("<input type=text name=question size=100><br><br>");
echo ("<input type=submit value=Ask! name=ask>");
echo ("</form>");
echo ("<hr><br><br>");
if (isset($_POST['question'])){
$question=strtolower(trim($_POST['question']));
echo ("Reply:<br><br>");
if($question==""){
echo ("Please enter a question. I'm not a mind reader!");
}
if(substr($question,0,3)=="who"){
echo ("You!");
}
if(substr($question,0,4)=="what"){
echo ("Something!");
}
if(substr($question,0,4)=="when"){
echo ("Sometime!");
}
if(substr($question,0,5)=="where"){
echo ("Somewhere!");
}
if(substr($question,0,3)=="why"){
echo ("Because!");
}
if(substr($question,0,3)=="how"){
if(substr($question,0,8)=="how many"){
echo mt_rand(1,10);
} else {
echo ("Some way!");
}
}
}
echo ("</body>");
echo ("</html>");
?>
Notice I do not escape back and forth between php and html but rather have php output all the desired html (improves server performance and simplifies things). (Dynaverse.net scripts need a lot of work in this respect.) Note that you can omit certain quotes useage in html output but can output actual quotations by escaping with a slash... i.e.: \" ...or a single quote will often do... I've omitted most of them in the html output by the script above but it is best to use proper quotes where needed.
Post your script here (minus passwords etc) if you like and I can take a look at it and see if I have any suggestions.
-
Ok its kinda ugly because I "wrote" it myself. heh ill dig it up and post in a few.
-
send.php (the PHP program doing that reads the forum and mails it).
<?php
include("config.inc.php");
$ip = $_SERVER['REMOTE_ADDR'] ;
$date = $_REQUEST['date'] ;
$name = $_REQUEST['fname'] ;
$day = $_REQUEST['day'] ;
$month = $_REQUEST['month'] ;
$year = $_REQUEST['year'] ;
$country = $_REQUEST['country'] ;
$state = $_REQUEST['state'] ;
$alias = $_REQUEST['alias'] ;
$email = $_REQUEST['email'] ;
$referrer = $_REQUEST['referrer'] ;
$gaming = $_REQUEST['gaming'] ;
$reason = $_REQUEST['reason'] ;
$fees = $_REQUEST['fees'] ;
$rules = $_REQUEST['rules'] ;
$message = "Hi $sitename,
$name has sent you an application on $date. The message is below including his/her IP address and email address:
ip: $ip
name : $alias 's Testimony
email : $email
subject : $alias 's Application
message : Date Submitted - $date
First Name - $name
Birthdate - $day $month $year
Country Residing - $country
State Residing (If in USA) - $state
Gaming Alias - $alias
Email Address - $email
Referrer - $referrer
Gaming Experience - $gaming
Reason for wishing to join - $reason
Willing to pay fees - $fees
Willing to follow rules - $rules
Thanks,
The administrator
-----------------------
Powered by SkyFlyer Webdesign";
if($logs == "1") {
$log = "$date, $ip, $name, $day, $month, $year, $country, $state, $alias, $email, $referrer, $gaming, $reason, $fees, $rules\r";
// Open the file and erase the contents
$fp = fopen("$logsfile", "a");
// Write the data to the file
$log = str_replace("\n", "", $log);
fwrite($fp, $log);
// Close the file
fclose($fp);
}
if($banip == "1") {
if(strstr($banip_list, $ip)) {
echo "<META http-equiv=\"refresh\" content=\"0; URL=$errorpage\">";
}
}
if($banemail == "1") {
if(strstr($banemail_list, $email)) {
echo "<META http-equiv=\"refresh\" content=\"0; URL=$errorpage\">";
}
}
if($autoresponder == "1") {
$autorespond_headers = "From: $sitename($address)";
@mail($email, $autorespondersub, $autorespondermess, $autorespond_headers);
}
@mail( "$address", "$subject", "$message", "From: $email");
echo "<META http-equiv=\"refresh\" content=\"0; URL=$donepage\">";
?>
Config.inc.php (the variables).
<?php
/* SkyFlyer's forms
*/
//
// Setup
//
$sitename = "clanlessfraggers.com"; // Site Name
$address = "admin@sky-flyer.org"; // Where to send all emails!
$dir = ""; // Directory where script is installed. eg Site is
// in /. Script is in /contact and it is included you
// would put /contact/. If you accessed the file in
// the /contact/ folder then you would leave it blank
//
// AutoResponse
//
// WARNING : DON'T WRITE ANY " IF YOU DO PUT A \ BEFORE IT, EG.
// \"Administrator\". THIS WILL SHOW AS "ADMINISTRATOR".
// LEAVE BLANK TO DISABLE.
//
$autoresponder = "0"; // Status, 0 = off 1 = on
$autorespondersub = "Thanks for your mail"; // Autoresponder Subject
$autorespondermess = "Hi,
Thanks for your application you sent to us.
We have recieved the application and will review its content
as soon as possible,
Regards,
Site Administrators"; // Autoresponder Email
//
// Logs
//
$logs = "1"; // Create Logs, 0 = off 1 = on
$logsfile = "logs.txt";
//
// Banned
//
$banip = "1"; // Ban IP's, 0 = off 1 = on
$banip_list = "111.222.33.44,555,666,77,88"; // Banned IP's, seperate by comma
$banemail = "1"; // Ban Emails, 0 = off 1 = on
$banemail_list = "test@test.com,test2@test2.com"; // Banned Emails, seperate by comma
//
// Field Limits
//
// WARNING : ONLY ENTER NUMBERS IN THE ", NOTHING ELSE!
//
//
// Error/Done Pages
//
$donepage = "done.html"; // Thank You/Done page
$errorpage = "error.html"; // Banned IP/Email Page.
?>
-
Ohh Nice the PHP tags work. Did that come with SMF or is that a mod, bonk? If its a mod can you send it to me?
-
Resolved :)
-
glad you worked it out... :) (I'm not on the boards much at the moment, sorry)
Not sure about the PHP code tags here, I seem to remember something about it... a setting somewhere... I'll see if I can find it when I get the chance.
-
Yeah it turned out one of the very first things I tried actually worked... just my spam blocker caught it.
-
Ohh Nice the PHP tags work. Did that come with SMF or is that a mod, bonk? If its a mod can you send it to me?
...seems its been built into SMF for a while now: 8)
http://www.simplemachines.org/community/index.php?topic=1621.0
testing:
<?php
echo "Hello!";
?>
<?php
echo "Hello!";
?>
it seems it likes to see the <?php code here; ?> php syntax to work properly, if you leave the leading <?php tag out it doesent work right inside a code tag.
-
This is a test: Please ignore the contents of this post.
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write("Testing the RandomNumber Component<hr>");
//Display the properties of the component
Response.Output.Write("MinValue: {0}, "+
"MaxValue: {1}",
randomNumber1.MinValue,
randomNumber1.MaxValue);
Response.Write("<br>");
//Call the method fo the component
Response.Output.Write("Generate Random "+
"Number: {0}",
randomNumber1.GenerateRandomNumber());
}
Hmmm...interesting.
Jerry