PHP - E-mailing Php Code
Hi all,
I have a problem with emailing php code using a php function. using the code below, It emails the message 2 times with blank content. I think the problem might be with the eval() or file_get_content(), because if I comment it out the eval() and replace $message with a static value, it sends the message once with the static content. The functions safeText (which does a mysql_real_escape_string), returnShopName (which returns the shop name) and returnShopEmailURL(which returns the url of the shop minus the http://www) all work, as they are used in other functions. here is the function: Code: [Select] <?php //Email a link to the voucher function emailVoucher($id) { //Ensure no one can use a combined URL and SQL Injection attack, as it comes from a $_GET $id = safeText($id); //Query the database, count the results and make an array to hold them $query = mysql_query("SELECT * FROM shop_vouchers WHERE voucher_id = '".$id."' LIMIT 1") or die ('Error: '.mysql_error()); $count = mysql_num_rows($query); $fetch = mysql_fetch_array($query); //If there are results if($count == 1) { $to = $fetch["voucher_email"]; $subject = 'Your voucher from '.returnShopName(); $headers = 'From: website@'. returnShopEmailURL() . "\r\n" . 'Reply-To: no-reply@'. returnShopEmailURL() . "\r\n" . 'X-Mailer: PHP/' . phpversion() . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html' . "\r\n"; $link = 'http://www.example.com/vouchers.php?email=1'; $name = returnShopName(); $URL = returnShopEmailURL(); $body = file_get_contents('includes/voucher_email.php'); eval("\$body = \"$message\";"); mail($to, $subject, $message, $headers); gotoURL("vouchers.php?issue=1"); }else{ //Popup error message and redirect echo '<script type="text/javascript">'; echo 'alert("An error occurred. Please try again.")'; echo '</script>'; gotoURL("vouchers.php"); } } ?> the code in voucher_email.php (for testing purposes) is: Code: [Select] $name 1, $link 2, $URL 3 Similar TutorialsSomebody please tell me why this wont work. Didnt wont to put my email in their. <?php $user = $_POST['subject']; $email = $_POST['email']; $message = $_POST['message']; //To, Subject, Message mailto(''); mailsubject('$user Sent you a message'); mailfrom('From: ' . $user . ' <' . $email . '>'); ?> First off, hello. This is my first pHp code, and still tying to get a grasp on it all. This is the pHp i have for my mailing form. Now i wish to make the user have to put in a valid email address. Except it isn't working for me. The following script isn't coming up with any errors, but it is still letting the email field be submitted with any text. <?php if ($_POST['submit']) { $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; $errorstring = ""; if (!$name) $errorstring = $errorstring."Name<br>"; if (!$email) $errorstring = $errorstring."email<br>"; if (!$comments) $errorstring = $errorstring."comments<br>"; if ($errorstring!="") echo "You missed the following:<br>$errorstring"; else { $webMaster = "name@site.com"; $emailSubject = "Contact Us Form"; $mail_from = "$email"; $name = $_POST['name']; $email = $_POST['email']; $comments = $_POST['comments']; function valid_email($email) { if(eregi("^[\w\-]+?\@\w+?\.\w+$", $email)) { return TRUE; } else { return FALSE; } } if (!valid_email($email)) { die('bad email'); } $body = ' <br> Name ' . $name . ' <br><br> ' . $email . ' <br><hr><br> Comments<p> ' . $comments . ' '; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); $redirect = file_get_contents('redirect.html'); echo $redirect; } } ?> Thank you. I have a mail list script, problem is if I have to many mails sent at one time my website will be suspended. What should I do? Hello, I know very little about PHP, i am a graphics and HTML guy , i had a simple mailing list script up on a clients page for a couple years, and now all of a sudden it has stopped working. When you enter your name, and email, you get "select fails" and it does not get added to the database. Here is the code, any help would be great, i am lost since nothign has changed, but it just stoppped working. from the config.php file Code: [Select] function insert_mail() { $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $sql2="select * from mail where email='$email'"; $result2=mysql_query($sql2) or die("select fails"); $no=mysql_num_rows($result2); if ($no==0) { $sql = "insert into mail(id,fname,lname,email) values(NULL,'$fname','$lname','$email')"; $result = mysql_query($sql) or die("insert fails"); echo "Email added to list: " . LISTNAME; } else { echo "Email Address Already Exists in List: " . LISTNAME; } } function delete_mail() { $email = $_POST['email']; if ($email == "") { $email = $_GET['email']; } $sql2="select * from mail where email='$email'"; $result2=mysql_query($sql2) or die("select fails"); $no=mysql_num_rows($result2); if ($no==0) { echo "Your email was not found in the list: " . LISTNAME; } else { echo "Your email was unsubscribed from the list: " . LISTNAME; } $sql2="delete from mail where email='$email'"; $result2=mysql_query($sql2) or die("unsubscribe failed, please try again"); } ?> From the HTML Code: [Select] <center> <form action='<? echo BASEHREF; ?>index.php' method=post> <TABLE BORDER=0 ALIGN=center> <TR> <TD><b>first name</b></TD> <TD><INPUT TYPE=text name=fname></TD> </TR> <TR> <TD><b>last name</b></TD> <TD><INPUT TYPE=text name=lname></TD> </TR> <TR> <TD><b>email</b></tD> <TD><INPUT TYPE=text name=email></td> </tR> <TR> <TD colspan=2 align=center><INPUT TYPE=submit value=join> <INPUT TYPE=reset value=reset><BR></TD> </tR> </TABLE> </FORM> </center> Let me know what else you may need.... I have email's in mysql... how do i automatically send emails every week. I know how to send mail with php. How do i automatically send it every week? I'm trying to send an email that has a list created from a while loop to multiple people with an email list created from while loop. Can someone please help me figure this out? My brain is fried. Here's the code that I have: This is producing an error message that reads: Parse error: syntax error, unexpected '{' in /home/content/29/6879529/html/calhoun/admin/sendreport.php on line 22 Code: [Select] <?php include("conf.inc.php"); $result = mysql_query("SELECT `prefix`,`lname`,`email` FROM admin"); $row = mysql_fetch_row($result); $result2 = mysql_query("SELECT `to`,`from`,`subject`,`message`,`date` FROM allmsgs WHERE reported = 'n' ORDER BY `messid` ASC"); $row2 = mysql_fetch_row($result2); $cdate = date('m-d-Y'); while ($row = mysql_fetch_row($result)) { $prefix = $row[0]; $lname = $row[1]; $adminemail = $row[2]; $fullname = "$prefix $lname"; $sendto = "$adminemail"; $emailsubject = "Webstats Report For $cdate."; while ($row2 = mysql_fetch_row($result2){ // This is line 22. $to = $row2[0]; $from = $row[1]; $subject = $row[2]; $message = $row[3]; $datetime = $row[4]; $eachmessage = "<p> <hr width=\"400\"> To: $to<br> From: $from<br> On $datetime<br> <br> $subject<br>$nbsp;<br> $message </p>"; } $emailmessage = "<html> <body> $fullname, <p> Here is a list of the messages that have been exchanged in the last 24 hours.</p> $eachmessage </body> </html>"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Webstats <reports@webstats.com>' . "\r\n"; // Mail it mail($sendto, $emailsubject, $emailmessage, $headers); } ?> I'm using 3 files to try and mass mail my members, massmail.php massmail-exe.php and elist.php massmail.php <form name="massmail" method="post" action="./massmail-exe.php"> <table width="450px"> <tr> <td valign="top"> <label for="subject">Subject</label> </td> <td valign="top"> <input type="text" name="subject" maxlength="50" size="30" id="subject"> </td> </tr> <tr> <td valign="top"> <label for="message">Email Content</label> </td> <td valign="top"> <textarea name="message" maxlength="9001" cols="100" rows="18" id="message"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"> </td> </tr> </table> </form> massmail-exe.php <?php // read the list of emails from the file. $email_list = file("./elist.php"); // count how many emails there are. $total_emails = count($email_list); // go through the list and trim off the newline character. for ($counter=0; $counter<$total_emails; $counter++) { $email_list[$counter] = trim($email_list[$counter]); } // implode the list into a single variable, put commas in, apply as $to value. $to = implode(",",$email_list); if ( mail($to,$_POST["subject"],$_POST["message"]) ) { echo "The email has been sent!"; } else { echo "The email has failed!"; } ?> and elist.php which has the email addresses. What is wrong because every time i try and send it it say query failed. Thanks so much. Hi guys, I was just wondering if anyone could help me. I've got a My_SQL database containing articles, a summary for the article and a date. I have a basic CMS system set-up, but I want to create a script that when users sign up to a mail list it forwards the summary and dates of the articles database. If that makes sense? But I only want it to forward the most recent 5 rows. I'm pretty new to PHP and I've been mostly following tutorials thus far, but this is quite specific. Thanks in advance! Hi, I am new to this forum and hopefully u guys can help me solve the problem i have in this first post! So please take a look at this html script <html> <head> <title>Sub/Unsub</title> </head> <body> <h1> Subscribe or unsubscribe mailing list</h1> <form method=POST action="manage.php"> <p><b>Your E-mail address:</b></br> <input type=text name="email" size=40 maxlength=150> <p><b>Action:</b></p> <input type=radio name="action" value="sub" checked>Subscrbie <input type=radio name="action" value="unsub">Unsubscribe <p><input type=submit name="submit" value="Submit form"></p> </form> </body> </html> And this is the manage.php script: <?php //set up a couple of functions include('connect.php'); function emailChecker($email){ global $connect, $check_result; //check mail is not already in list $check = "select id from users where email = '$email'"; $check_result = mysqli_query($connect, $check) or die(mysqli_error($connect)); } if ( ($_POST[action] == 'sub')){ //Try to subscribe, so validate email if($_POST[email]=""){ hearder("Location: manage_start.php"); exit(); } //connect to database db(); //check if email is on the list emailChecker($_POST[email]); //check the number of results to look for duplicates if (mysqli_num_rows($check_result)<1){ //since no records detected, so add this new email $sql="INSERT into users (email) values('$_POST[email]')"; $result = mysqli_query($connect, $sql) or die(mysqli_error($connect)); echo "<p>Thanks for signing up man!!</p>"; } else { //print failure message echo "<p>You have already subscribed!</p>"; } } else if (($_POST[action] == "unsub")){ //trying to unsubscribe and validate address if ($_POST[email] == "") { header ("Location: manage_start.html"); exit(); } db(); emailChecker($_POST[email]); if (mysqli_num_rows($check_result) <1) { //print failure message echo "<p>Cannot find your address!</p> <p>No action is taken</p>"; } else { //unsubscribe address $id = mysqli_real_escape_string($connect, $_POST['id']); $sql = "DELETE from users where id = '$id'"; $result = mysqli_query($connect, $sql) or die(mysqli_error()); echo "<p>You have unsubscribed!</p>"; } } ?> So wut i am trying to do in this script is to create a mailing list form for user to subscribe/unsubscribe using email address. When i first run the html script (which includes php script) and subscribe by the first time, it went perfectly fine and it echos "thanks for signing up man!!" but when i try it with the totally DIFFERENT email address, it always says "You have already subscribed!!" Even when i put blank on the address box, it still shows "You have already subscribed!!" Also it's the same deal as unsubscribe, first time i could delete an entry from my database completely, but afterward when i try to delete the exact email addresses from database, it wouldn't work !! It just says "You have unsubscribed!" but when i checked back if the entry has been deleted, the answer is NO ! I am wondering if this is the problem about $global values under function emailChecker( ). Btw my database connection works absolutely fine. I know this is a long ass post but i need an urgent answer PLZZZZZZZZ Hi, PHP beginner here.
I'm trying to run a very basic script which does the following:
1) Input some data into a form
2) Outputs the data onto the screen
3) Click submit and e-mail it to me.
The purpose of it is simply to learn how to input some data, output that data along with some basic calculations and then to send that data to an e-mail address.
#1 & #2 I can do. I can enter some text and some numbers and on the next screen I can print a message containing the data I put into the form.
Also I am taking the variables and doing some calculations which is fine.
However, when I click submit (on the second screen) to e-mail the data to me, I am getting an e-mail but none of the variables have retained the data.
FORM
<html> Hey everyone I'm pretty new at PHP so i'm hoping someone can help me with this code. What I am trying to do is if someone selects a state say Kansas then fills out the rest of the form and clicks submit it will go to a specific email address. If someone selects another state like Nebraska it will go to a separate email address. Here is my code and I hope someone can help me with this. PS I think I really screwed this one up lol :help: Thanks, B Code: [Select] <?php /* Subject and Email variables */ $emailSubject = 'Your Car Report Info.'; $webMaster = 'me@rustyeckford.com'; $webMaster2 ='me1@rustyeckford.com'; $webMaster3 ='me2@rustyeckford.com'; /* Gathering Data Variables */ $f_nameField = $_POST['f_name']; $l_nameField = $_POST['l_name']; $addField = $_POST['Address']; $stateField = $_POST['state']; $phoneField = $_POST['phone']; $emailField = $_POST['email']; $vinField = $_POST['vin']; $body = <<<EOD <br><hr><br> First Name: $f_name <br> Last Name: $l_name <br> Address: $Address <br> State: $state <br> Phone: $phone <br> Email: $email <br> VIN: $vin <br> EOD; switch($state) { case 'Kansas': case 'Oklahoma': $wm = $webMaster2; break; case 'Missouri': case 'Iowa': $wm = $webMaster3; break' case 'Nebraska: $wm = $webMaster; break; } $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($wm, $emailSubject, $body, $headers); /* Results rendered from Html */ $theResults = <<<EOD <html> <head> <title>Your Car Report - Results</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> body { background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; } </style> </head> <div> <div align="center">Thank you for your submission. Your vehicle report will be provided to you very soon!</div> </div> </body> </html> EOD; echo "$theResults"; ?> <?php //Database Credentials include "../db_fns.php"; session_start(); //Database connection $conn = db_connect_2(); if (isset($_SESSION['link']) AND !isset($_POST['Submit'])){ //retrieve link if(is_string($_SESSION['link'])){ $link = unserialize($_SESSION['link']); } else { $link = $_SESSION['link']; } if($link){ //basic stuff $_SESSION['transgene_type'] = (string)$link->tt_id; $_SESSION['promoter_locus'] = $link->promoter; $_SESSION['PromoLocusSynonyms'] = $link->pl_synonyms; $_SESSION['species'] = (string)$link->s_id; //genetic background //clear it just incase there are values since another time $_SESSION['genetic_bg'] = array(); $_SESSION['GeneticBGOtherTxt'] = ""; foreach($link->genetic_bg as $gbg){ //we check if it is a menu selected item or an item that is not in menu if((int)$gbg['GBG_IS_MENU']){ $_SESSION['genetic_bg'][] = $gbg['GBG_ID']; } else { //belongs in other if(empty($_SESSION['GeneticBGOtherTxt'])) { $_SESSION['GeneticBGOtherTxt'] .= $gbg['GBG_NAME']; } else { $_SESSION['GeneticBGOtherTxt'] .= ",".$gbg['GBG_NAME']; } } } $_POST = $_SESSION; }elseif (isset($_POST['Submit'])) { if(isset($_SESSION['link'])) { //we need to unserialize the link if(is_string($_SESSION['link'])){ $link = unserialize($_SESSION['link']); //unserialize() takes a single variable and converts it back into a php value } else { $link = $_SESSION['link']; } } //put $_POST variables into $_SESSION $_SESSION = $_POST + $_SESSION; unset($_SESSION['Submit']); // CHECK FOR ERRORS AFTER SUBMISSION $errors = array(); // Set array if (!$_POST['promoter_locus']) $errors[] = "Please specify a value for \"Promoter or Locus\"".$PromoLocus; if (!$_POST['transgene_type']) $errors[] = "Please specify a value for \"Transgene Type\""; if (!$_POST['inducible_systems'] && !$_POST['InducibleSystemsOther']) $errors[] = "Please specify an \"Inducibility\" value"; } if (count($errors) > 0 ) { $iferrors = "Yes"; } else { [SIZE="4"][B][U] include ('mailing_list.php'); checkPromoter($_POST['promoter_locus'];[/U][/B][/SIZE] //this is to check that step one has been completed once we go to step 2 $_SESSION['step'] = 2; header("Location: StepTwo_2.php"); exit; } } } else { session_trash_(); session_regenerate_id(true); } Note that this script is an excerpt and I make the lines that I put to be bold and underlined. This is the mailing_list.php <?php require('connection.php'); function checkPromoter ($_POST['promoter_locus']) { $check = "select id from mailing_list where query = '$_POST['promoter_locus']'"; $result = mysqli_query($connect, $check) or die(mysqli_error($connect)); if (mysqli_num_rows($result)==0){ continue; } else { $sql = "select email from mailing_list where query = '$_POST['promoter_locus']'"; $query = $_POST['promoter_locus']; $email = mysqli_query($connect, $sql) or die(mysqli_erro($connect)); $to = $email; $subject = "The query is updated"; $headers = "From: asdfasdf"; $body = " Hello This is to inform you that $query is updated, please go to this link to search for it: http://asdfasdf Regards, asdfasdf."; mail($to, $subject, $body, $headers); die(); } } So my questions are 1. Where should I place those bold lines in addEntry.php? I tried to run it but the result is a blank page... Also there's no email sending through to my test email 2. For the line function checkPromoter ($_POST['promoter_locus']), should I put variable like $promoter = $_POST['promoter_locus'] ? Cuz I ran that and the error is Parse error: syntax error, unexpected '[', expecting ')' 3. Can u guys please help me fix up mailing_list.php? thanks for ur patience to read thru this and ANY HELP IS APPCRECIATED :p Hi I have been given a task to create some SQL reports. One of the reports is to display all the customers who have purchased a certain product based on user selection and then have those results able to be extracted to a mailing list. So ive got the report done. Some drop down boxes allow a user to select a product and once submitted the results are then displayed. But i dont even know where to begin with extracting those results to a mailing list. Could someone help me please? What method should I use? and where do i begin? BTW im a rookie with PHP/Mysql ive just got my first job since leaving university and this is a task ive been given at work so any quick and helpful replies are greatly appreciated Thanks in advance. what I am trying to do is use this php script to load the data being submitted in the html form into my database and then populate the database into an excel (xls) file and then e-mail it to my address. Everything works great it populates into the database and creates the xls file perfect. But it is wanting me to download the file. What can I add to the script to have it e-mail the file to my e-mail address INSTEAD of downloading it. Code: [Select] <?php define('DB_NAME', 'database'); define('DB_USER', 'username'); define('DB_PASSWORD', 'password'); define('DB_HOST', 'hostname'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $link); if (!$db_selected) { die('Can\'t use ' . DB_NAME . ': ' . mysql_error()); } $value1 = $_POST['groupname']; $value2 = $_POST['name']; $value3 = $_POST['address']; $value4 = $_POST['city']; $value5 = $_POST['state']; $value6 = $_POST['zip']; $value7 = $_POST['homephone']; $value8 = $_POST['cellphone']; $value9 = $_POST['email']; $value10 = $_POST['age']; $value11 = $_POST['maritalstatus']; $value12 = $_POST['income']; $value13 = $_POST['contact1']; $value14 = $_POST['contact2']; $value15 = $_POST['contact3']; $value16 = $_POST['date1']; $value17 = $_POST['date2']; $value18 = $_POST['date3']; $sql = "INSERT INTO clients (groupname, name, address, city, state, zip, homephone, cellphone, email, age, maritalstatus, income, contact1, contact2, contact3, date1, date2, date3) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } mysql_close(); mysql_connect('hostname', 'username', 'password'); mysql_select_db('database'); $sql = "SELECT `groupname` AS `Group`, `name` AS `Customer Name`, `address` AS `Address`, `city` AS `City`, `state` AS `State`, `zip` AS `Zip Code`, `homephone` AS `Home Phone`, `cellphone` AS `Cell Phone`, `email` AS `E-Mail`, `age` AS `Age Group`, `maritalstatus` AS `Marital Status`, `income` AS `Household Income`, `contact1` AS `Contact VIA`, `contact2` AS `Contact VIA`, `contact3` AS `Contact VIA`, `date1` AS `1st Date`, `date2` AS `2nd Date`, `date3` AS `3rd Date` FROM fundtour_info.clients clients"; // Query Database $result=mysql_query($sql); $filename = 'file.xls'; // Send Header header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download");; header("Content-Disposition: attachment;filename=$filename"); header("Content-Transfer-Encoding: binary "); // XLS Data Cell xlsBOF(); xlsWriteLabel(0,0,"Group"); xlsWriteLabel(0,1,"Name"); xlsWriteLabel(0,2,"Address"); xlsWriteLabel(0,3,"City"); xlsWriteLabel(0,4,"State"); xlsWriteLabel(0,5,"Zip Code"); xlsWriteLabel(0,6,"Home Phone"); xlsWriteLabel(0,7,"Cell Phone"); xlsWriteLabel(0,8,"E-mail Address :"); xlsWriteLabel(0,9,"Age Group"); xlsWriteLabel(0,10,"Marital Status"); xlsWriteLabel(0,11,"Income"); xlsWriteLabel(0,12,"Contact Via"); xlsWriteLabel(0,13,"Dates"); $xlsRow = 1; while(list($groupname,$name,$address,$city,$state,$zip,$homephone,$cellphone,$email,$age,$maritalstatus,$income,$contact1, $contact2, $contact3,$date1, $date3, $date3)=mysql_fetch_row($result)) { ++$i; xlsWriteLabel($xlsRow,0,"$groupname"); xlsWriteLabel($xlsRow,1,"$name"); xlsWriteLabel($xlsRow,2,"$address"); xlsWriteLabel($xlsRow,3,"$city"); xlsWriteLabel($xlsRow,4,"$state"); xlsWriteLabel($xlsRow,5,"$zip"); xlsWriteLabel($xlsRow,6,"$homephone"); xlsWriteLabel($xlsRow,7,"$cellphone"); xlsWriteLabel($xlsRow,8,"$email"); xlsWriteLabel($xlsRow,9,"$age"); xlsWriteLabel($xlsRow,10,"$maritalstatus"); xlsWriteLabel($xlsRow,11,"$income"); xlsWriteLabel($xlsRow,12,"$contact1, $contact2, $contact3"); xlsWriteLabel($xlsRow,13,"$date1, $date3, $date3"); $xlsRow+++; } xlsEOF(); exit(); function xlsBOF() { echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); return; } function xlsEOF() { echo pack("ss", 0x0A, 0x00); return; } function xlsWriteNumber($Row, $Col, $Value) { echo pack("sssss", 0x203, 14, $Row, $Col, 0x0); echo pack("d", $Value); return; } function xlsWriteLabel($Row, $Col, $Value ) { $L = strlen($Value); echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); echo $Value; return; } ?> Thanks for any help Hey, been trying to make a form to upload an image to the server and also email the image as attachment. After nearly a week I managed to make it work. Only some validation needs to be done. My next step is to make it work for multiple files, ie. 5. The form will have 5 boxes to upload images and no more. I have tried a few different things with for loops ( ie for $i=0; $i<5; $i++ {...} ) but no luck. I can't think of any solution of a loop to upload multiple files and then email multiple attachment as my code. The code is: <?php session_start(); $imagename1 = $_FILES["uploadFile1"]["name"]; $_SESSION['imagename1'] = $imagename1; $imagename1 = $_SESSION['imagename1']; $imagetype1 = $_SESSION['imagetype1']; $imagesize1 = $_SESSION['imagesize1']; $imagetemp1 = $_SESSION['imagetemp1']; $thankyouurl = 'thankyou.php' ; $errorurl = 'error.php' ; $http_referrer = getenv( "HTTP_REFERER" ); $http_agent = getenv( "HTTP_USER_AGENT" ); $domain = $_SERVER['REMOTE_ADDR']; $filename = $_SESSION['uploadFilename']; if(isset($_POST['send'])) { $fp = fopen($imagetemp1, "rb"); $file = fread($fp, $imagesize1); $file = chunk_split(base64_encode($file)); $num = md5(time()); fclose($fp); // UPLOAD FILE // possible PHP upload errors $errors = array(1 => 'php.ini max file size exceeded', 2 => 'html form max file size exceeded', 3 => 'file upload was only partial', 4 => 'no file was attached'); // check the upload form was actually submitted else print form isset($_POST['send']) or error('the upload form is neaded', $uploadForm); // check for standard uploading errors ($_FILES[$fieldname1]['error'] == 0) or error($errors[$_FILES[$fieldname1]['error']], $uploadForm); // check that the file we are working on really was an HTTP upload @is_uploaded_file($_FILES[$fieldname1]['tmp_name']) or error('not an HTTP upload', $uploadForm); // validation... since this is an image upload script we // should run a check to make sure the upload is an image @getimagesize($_FILES[$fieldname1]['tmp_name']) or error('only image uploads are allowed', $uploadForm); // make a unique filename for the uploaded file and check it is // not taken... if it is keep trying until we find a vacant one $now = date("y-m-d_H-i-s", time()); while(file_exists($uploadFilename = $uploadsDirectory.$now.'_'.$_FILES[$fieldname1]['name'])) { $now++; } // now let's move the file to its final and allocate it with the new filename @move_uploaded_file($_FILES[$fieldname1]['tmp_name'] , $uploadFilename) or error('receiving directory insuffiecient permission', $uploadForm); $from= 'youremail@server.co.uk'; $emailTo = 'mail@hotmail.com'; $subject = 'Quote Form'; $body = "equipment_type: $equipment_type \n\nModel: $Model \n\nMake: $Make \n\nModelNumber: $ModelNumber"; $fp = $_SESSION['fp']; $file = $_SESSION['file']; $num = "==Multipart_Boundary_x{$semi_rand}x".$_SESSION['num']; $headers = 'From: Name <'.$from.'>' . "\r\n" . 'Reply-To: ' . $emailTo; //Normal headers $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; "; $headers .= "boundary=".$num."\r\n"; $headers .= "--$num\r\n"; // This two steps to help avoid spam $headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; $headers .= "X-Mailer: PHP v".phpversion()."\r\n"; // With message $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 8bit\r\n"; $headers .= "".$body."\n"; $headers .= "--".$num."\n"; // Attachment headers $headers .= "Content-Type:".$imagetype1." "; $headers .= "name=\"".$imagename1."\"r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "Content-Disposition: attachment; "; $headers .= "filename=\"".$imagename1."\"\r\n\n"; $headers .= "".$file."\r\n"; $headers .= "--".$num."--"; mail($emailTo, $subject, $body, $headers); header( "Location: $thankyouurl" ); } ?> the form is like this Code: [Select] <input name="uploadFile1" id="uploadFile1" value="" class="file" type="file"/>can anyone suggest anything please? how can I form the for statement? much appreciated Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this? <?php include ("includes/includes.php"); $blogPosts = GetBlogPosts(); foreach ($blogPosts as $post) { echo "<div class='post'>"; echo "<h2>" . $post->title . "</h2>"; echo "<p class='postnote'>" . $post->post . "</p"; echo "<span class='footer'>Posted By: " . $post->author . "</span>"; echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>"; echo "<span class='footer'>Tags: " . $post->tags . "</span>"; echo ' <div class="addthis_toolbox addthis_default_style "> <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a> <a class="addthis_button_tweet"></a> <a class="addthis_counter addthis_pill_style"></a> </div> <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>'; echo "</div>"; } ?> I have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. Hi, I need to insert some code into my current form code which will check to see if a username exist and if so will display an echo message. If it does not exist will post the form (assuming everything else is filled in correctly). I have tried some code in a few places but it doesn't work correctly as I get the username message exist no matter what. I think I am inserting the code into the wrong area, so need assistance as to how to incorporate the username check code. $sql="select * from Profile where username = '$username'; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(mysql_num_rows($result)!=0) { process form } else { echo "That username already exist!"; } the current code of the form <?PHP //session_start(); require_once "formvalidator.php"; $show_form=true; if (!isset($_POST['Submit'])) { $human_number1 = rand(1, 12); $human_number2 = rand(1, 38); $human_answer = $human_number1 + $human_number2; $_SESSION['check_answer'] = $human_answer; } if(isset($_POST['Submit'])) { if (!isset($_SESSION['check_answer'])) { echo "<p>Error: Answer session not set</p>"; } if($_POST['math'] != $_SESSION['check_answer']) { echo "<p>You did not pass the human check.</p>"; exit(); } $validator = new FormValidator(); $validator->addValidation("FirstName","req","Please fill in FirstName"); $validator->addValidation("LastName","req","Please fill in LastName"); $validator->addValidation("UserName","req","Please fill in UserName"); $validator->addValidation("Password","req","Please fill in a Password"); $validator->addValidation("Password2","req","Please re-enter your password"); $validator->addValidation("Password2","eqelmnt=Password","Your passwords do not match!"); $validator->addValidation("email","email","The input for Email should be a valid email value"); $validator->addValidation("email","req","Please fill in Email"); $validator->addValidation("Zip","req","Please fill in your Zip Code"); $validator->addValidation("Security","req","Please fill in your Security Question"); $validator->addValidation("Security2","req","Please fill in your Security Answer"); if($validator->ValidateForm()) { $con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error()); mysql_select_db("beatthis_beatthis") or die(mysql_error()); $FirstName=mysql_real_escape_string($_POST['FirstName']); //This value has to be the same as in the HTML form file $LastName=mysql_real_escape_string($_POST['LastName']); //This value has to be the same as in the HTML form file $UserName=mysql_real_escape_string($_POST['UserName']); //This value has to be the same as in the HTML form file $Password= md5($_POST['Password']); //This value has to be the same as in the HTML form file $Password2= md5($_POST['Password2']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $Zip=mysql_real_escape_string($_POST['Zip']); //This value has to be the same as in the HTML form file $Birthday=mysql_real_escape_string($_POST['Birthday']); //This value has to be the same as in the HTML form file $Security=mysql_real_escape_string($_POST['Security']); //This value has to be the same as in the HTML form file $Security2=mysql_real_escape_string($_POST['Security2']); //This value has to be the same as in the HTML form file $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } mysql_close($con); $show_form=false; } else { echo "<h3 class='ErrorTitle'>Validation Errors:</h3>"; $error_hash = $validator->GetErrors(); foreach($error_hash as $inpname => $inp_err) { echo "<p class='errors'>$inpname : $inp_err</p>\n"; } } } if(true == $show_form) { ?> hey gurus, i am a newbie php coder.. i am learning by example. what i am trying to do is write a piece of code which will alter 3 tables (user, bonus_credit, bonus_credit_usage) ---------------------------------------------------------------- the table structure that will be used is as follows: user.bonus_credit user.ID bonus_credit.bonusCode bonus_credit.qty bonus_credit.value bonus_credit_usage.bonusCode bonus_credit_usage.usedBy ---------------------------------------------------------------- so lets say, in bonus_credit i have the following bonusCode = 'facebook' (this is the code they have to type to redeem the bonus qty = '10' ( number of times the bonusCode can be redeemed, but same person can't redeem it more than once) value = '5' (this is the amount of bonus_credit for each qty) Now, I need to write a code that check to see if the code has been redeemed in the bonus_credit_usage table and if the user.ID exists in this table as bonus_code_usage.usedBy, then give an error that its already been used and if it hasn't been used, then subtract 1 from qty, add ID to usedBy and then add the value to the bonus_credit ----------------------- i have started the steps just to create a simple textbox and entering a numeric value to bonus_credit, and that works.. but now i have to use JOIN and IF and ELSE.. which is a little too advanced for me.. so i'd appreciate a guide as i write the code. if(isset($_REQUEST['btnBonus'])) { $bonus_credit = addslashes($_REQUEST['bonusCode']); $query = "update user set bonus_credit=bonus_credit+'".$bonus_credit."' where id='".$_SESSION['SESS_USERID']."'"; echo "<script>window.location='myreferrals.php?msgs=2';</script>"; mysql_query($query) or die(mysql_error()); } |