PHP - Emailing Each Record Of Database
I have a database with three fields: name, email, and event. People signed on through a form and provided this information each time they wanted a ticket to attend Thanksgiving, Christmas, and New Years parties.
Now I want to contact them by email WITHOUT using a CC or BCC function because I do NOT want my messages filtered as spam. How can I send each person a single email? Similar TutorialsI have finaly got my removing recods page working, but i do have one problem... i have a delete button which goes to a new php page which contains the DELETE FROM, this deletes the record automaticaly. There are two paths which i could choose from the problem is i am stuck on both of them. 1. a link that will activate the delete code. 2. once the record has been deleted then it will automaticaly go back the the first page. can any one help me here please? CAN ANYONE TELL ME WHAT i AM DOING WRONG. I WANT TO RETRIEVE THE VERY FIRST RECORD IN MY DATABASE WHEN THE CODE EXECUTE IT ONLY SHOWS THE LAST RECORD IN THE DATABASE <?PHP $thisMonth = date('M'); $thisDay = date('j'); $eventMonth = array(); $eventDay = array(); $eventTime = array(); $eventName = array(); $eventLocation = array(); $dbMonth=""; $dbDay=""; $i=0; $conn = odbc_connect('eventsDB','',''); $sql= "SELECT month,day, time, event,location FROM Events"; $rs="$conn,$sql"; if (!$conn) { exit("Connection Failed: " . $conn); } $rs=odbc_exec($conn,$sql); if(!$rs) { exit("Error in SQL"); } echo "DATABASE OPEN"; while($i<3) { $dbMonth= odbc_result($rs,"month"); echo $eventMonth[$i]=odbc_result($rs,"month")."\n"; if($dbMonth<>$thisMonth) { odbc_fetch_row($rs); } echo $eventMonth[$i]=odbc_result($rs,"month")."\n"; echo $eventDay[$i]=odbc_result($rs,"day")."\n"; echo $eventTime[$i]=odbc_result($rs,"time")."\n"; echo $eventDay[$i]=odbc_result($rs,"event")."\n"; echo $eventLocation[$i]=odbc_result($rs,"location")."\n"; $i++; odbc_fetch_row($rs); echo $i; } //ends while loop odbc_close($conn); ?> [/code] Hi //open the connection $conn = mysql_connect("localhost", "techhom1_test", "pro176"); //pick the database to use mysql_select_db("testDB", $conn); //create the sql statement $sql = "INSERT INTO master_name values ('', '$firstname')"; //execute if (mysql_query($sql,$conn)){ echo "Record Added!"; } else{ echo "Somethin went wrong"; } the code above is insert code and working with out any errors but when i am submitting text into data using method below it is sending echo back Somethin went wrong.I think i am confused with the write name of the user table database is ***_test my tables are duty_number master_name in this _test user i am trying to add first name in master_name field so here is the submit code Code: [Select] <FORM ACTION=insert.php METHOD=POST> <P>text to add:<br> <input type=text name=master_name size=30> <p><input type=submit name=submit value=Insert Record></p> </FORM> My table below in Data base [code]Field Type Null Default Comments name_id smallint(5) Yes NULL name_dateaddedn datetime Yes NULL name_datemodified datetime Yes NULL firstname varchar(75) Yes NULL lastname varchar(75) Yes NULL can someone please look at the code and find the error for me Thanks Hi guys, I want a search to be done. That is when the user type the relevant customer id and clicks on search button the details of the customer should appear in a form. Therefore i tried the following code but it generates an empty form. All the customer details were stored in the database under customer table. customer(customer_id, full_name, name_with_initials, address, contact_number, gender) Can anyone show me where i went wrong? <?php $connect=mysql_connect("localhost","root",""); mysql_select_db("bank",$connect) or die ("could not select database"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- #apDiv4 { position:absolute; width:776px; height:598px; z-index:3; left: 206px; top: 300px; } #form1 { font-size: 18px; font-weight: bold; } body,td,th { font-size: 18px; } --> </style> </head> <body> <div id="apDiv4"> <form action="" method="post" name="form1" id="form1"> <fieldset> <legend class="cap"> Customer Details</legend> <table width="85%" height="350" border="0" align="center" cellpadding="5" cellspacing="0"> <?php if(isset($_POST['customer_id'])){ $customer_id=$_POST['customer_id']; $query = "select * from customer where customer_id=" .$customer_id; $result = mysql_query($query) or die(mysql_error()); while ($row=mysql_fetch_array($result)){ } ?> <tr> <td> </td> <td class="title02"> </td> <td> </td> <td> </td> </tr> <tr height="30"> <td width="2%" height="35"> </td> <td width="46%" class="title02" align="left">National ID</td> <td width="50%" class="attribute1" align="left"><input type="text" name="nic" size="30" class="attribute1" value="<?php echo $row['nic'];?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td height="33"> </td> <td width="46%" class="title02" align="left">Full Name</td> <td width="50%" class="attribute1" align="left"><input type="text" name="full_name" size="30" class="attribute1" value="<?php echo $row['full_name'];?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td height="34"> </td> <td class="title02" align="left">Name With Initials</td> <td width="50%" class="attribute1" align="left"><input type="text" name="name_with_initials" size="30" class="attribute1" value="<?php echo $row['name_with_initials'];?>"></td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Address</td> <td width="50%" class="attribute1" align="left"><label> <textarea name="address" id="textarea" cols="45" rows="5"><?php echo $row['address']; ?></textarea> </label></td> <td width="2%"> </td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Contact Number</td> <td width="50%" class="attribute1" align="left"><input type="text" name="contact_number" size="30" class="attribute1" value="<?php echo $row['contact_number']?>"></td> <td width="2%"> </td> </tr> <tr height="30"> <td width="2%"> </td> <td width="46%" class="title02" align="left">Sex</td> <td width="50%" class="attribute1" align="left"><p> <select name="gender" id="jumpMenu" > <option selected="selected"><?php echo $row['gender']; ?></option> <option>Male</option> <option>Female</option> </select> <td width="50%" class="attribute1" align="left"> </td> <br /> </p></td> <td width="2%"> </td> </tr> </table> <p align="center"> </p> <p align="center"> <label> </label> <label> <input name="button" type="submit" id="button" value="Approve Account" /> </label> <label> <a href="accsup_help.php"> <input name="button" type="submit" id="button" value="Help" /> </a></label> </td> </p> </fieldset> <td width="5%"> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> <tr> <td> </td> <td><font color="red" size="1" ></font></td> <td> </td> </tr> <?php } ?> </table> </form> </div> <img src="../images/mahapitiya 1.jpg" width="1024" height="139" /> </body> </html> Thanks, Not sure where to post this question. I have a MySQL database and add records with a PHP form to the tables. I have 2 fields (char) in one table. When the fields contain the character ' it wont write the record to the table! For example...if I enter. " John's house" it wont accept the record since ' appears in John's name! How do I work around this? Thanks Hello,
Here is my current code:
index.php
<html> <body> <form id="hey" name="hey" method="post" onsubmit="return false"> Name:<input type="text" name="name"> <input type="submit" name="submit" value="click"> </form> <table class="table table-bordered" id="update"> <thead> <th>Name</th> </thead> <tbody> <script type="text/javascript"> $("#hey").submit(function() { $.ajax({ type: 'GET', url: 'response.php', data: { username: $('#name').val()}, success: function (data) { $("#update").prepend(data); }, error: function (xhr, ajaxOptions, thrownError) { alert(thrownError); } }); }); </script> </tbody> </table>response.php <?php $username = $_GET['username']; echo "<tr>"; echo "<td>$username</td>"; echo "</tr>"; ?>This code works fine, it prints out the rows as what the user enters. Now what I want to do is, log all these entries to a mySQL database and also, display these rows over the site. i.e., any user who is online, should be seeing this without having to refresh the page too.. Real time updates in a way. How can I achieve that? Thanks! I have a MySQL database with each record of a person who has registered for an event, I am displaying the information on a web page for a user, but he wants to be able to print out all the records in alphabetical order by last name, first name later on so he will have a hard copy of each person who has registered at the table when they arrive. How can I write each record to a Txt file that he can print out later that will be formated with the record contents along with each fields definition (Ex. Last Name - Smith, First Name - John, etc)? I have 2 files; Newfault.php and thankyou.php 1) Data is entered into a form in Newfault.php 2) The data from this form is retieved in thankyou.php and is then inserted into a table called "Calls" Problem: My entered record is being added to my database OK, but it is also adding a blank record for some reason and I can't work out why. Can anyone help? This is for my uni assignment. Thanks, Ladykudos I have some code where I am inserting a record into a database. Code: [Select] <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require_once ('./includes/config.inc.php'); require_once (MYSQL); $add_cat_errors = array(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Check for a name: if (empty($_POST['product'])) { $add_cat_errors['product'] = 'Please enter the name!'; } // Check for a description: if (empty($_POST['prod_descr'])) { $add_cat_errors['prod_descr'] = 'Please enter the description!'; } // Check for a category: if (!isset($_POST['cat']) || !filter_var($_POST['cat'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $add_product_errors['cat'] = 'Please select a category!'; } // Check for a price: if (empty($_POST['price']) || !filter_var($_POST['price'], FILTER_VALIDATE_FLOAT) || ($_POST['price'] <= 0)) { $add_cat_errors['price'] = 'Please enter a valid price!'; } // Check for an image: if (is_uploaded_file ($_FILES['image']['tmp_name']) && ($_FILES['image']['error'] == UPLOAD_ERR_OK)) { $file = $_FILES['image']; $size = ROUND($file['size']/1024); // Validate the file size: if ($size > 512) { $add_cat_errors['image'] = 'The uploaded file was too large.'; } // Validate the file type: $allowed_mime = array ('image/gif', 'image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png'); $allowed_extensions = array ('.jpg', '.gif', '.png', 'jpeg'); $image_info = getimagesize($file['tmp_name']); $ext = substr($file['name'], -4); if ( (!in_array($file['type'], $allowed_mime)) || (!in_array($image_info['mime'], $allowed_mime) ) || (!in_array($ext, $allowed_extensions) ) ) { $add_cat_errors['image'] = 'The uploaded file was not of the proper type.'; } // Move the file over, if no problems: if (!array_key_exists('image', $add_cat_errors)) { // Create a new name for the file: $new_name = (string) sha1($file['name'] . uniqid('',true)); // Add the extension: $new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext); // Move the file to its proper folder but add _tmp, just in case: $dest = "../db/images/$new_name"; if (move_uploaded_file($file['tmp_name'], $dest)) { // Store the data in the session for later use: $_SESSION['image']['new_name'] = $new_name; $_SESSION['image']['file_name'] = $file['name']; // Print a message: echo '<h4>The file has been uploaded!</h4>'; } else { trigger_error('The file could not be moved.'); unlink ($file['tmp_name']); } } // End of array_key_exists() IF. } elseif (!isset($_SESSION['image'])) { // No current or previous uploaded file. switch ($_FILES['image']['error']) { case 1: case 2: $add_cat_errors['image'] = 'The uploaded file was too large.'; break; case 3: $add_cat_errors['image'] = 'The file was only partially uploaded.'; break; case 6: case 7: case 8: $add_cat_errors['image'] = 'The file could not be uploaded due to a system error.'; break; case 4: default: $add_cat_errors['image'] = 'No file was uploaded.'; break; } // End of SWITCH. } // End of $_FILES IF-ELSEIF-ELSE. // Check for a stock: if (empty($_POST['stock']) || !filter_var($_POST['stock'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $add_cat_errors['stock'] = 'Please enter the quantity in stock!'; } if (empty($add_cat_errors)) { $query = 'INSERT INTO product (product, product_descr, catID, price, image, stock) VALUES (?, ?, ?, ?, ?, ?)'; // Prepare the statement: $stmt = mysqli_prepare($dbc, $query); // For debugging purposes: // if (!$stmt) echo mysqli_stmt_error($stmt); // Bind the variables: mysqli_stmt_bind_param($stmt, 'isssdi', $name, $desc, $_POST['cat'], $_POST['price'], $_SESSION['image']['new_name'], $_POST['stock']); // Make the extra variable associations: $name = strip_tags($_POST['product']); $desc = strip_tags($_POST['prod_descr']); // Execute the query: mysqli_stmt_execute($stmt); if (mysqli_stmt_affected_rows($stmt) == 1) { // If it ran OK. // Print a message: echo '<h4>The product has been added!</h4>'; // Clear $_POST: $_POST = array(); // Clear $_FILES: $_FILES = array(); // Clear $file and $_SESSION['image']: unset($file, $_SESSION['image']); } else { // If it did not run OK. trigger_error('The product could not be added due to a system error. We apologize for any inconvenience.'); unlink ($dest); } } // End of $errors IF. } else { // Clear out the session on a GET request: unset($_SESSION['image']); } // End of the submission IF. require_once ('./includes/form_functions.inc.php'); ?> <form enctype="multipart/form-data" action="add_product.php" method="post" accept-charset="utf-8"> <input type="hidden" name="MAX_FILE_SIZE" value="524288" /> Product<br /><?php create_form_input('product', 'text', $add_cat_errors); ?> Description<br /><?php create_form_input('prod_descr', 'textarea', $add_cat_errors); ?> Category<br /><select name="cat"<?php if (array_key_exists('cat', $add_cat_errors)); ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = 'SELECT catID, cat FROM category ORDER BY cat ASC'; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['cat']) && ($_POST['cat'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('cat', $add_cat_errors)) echo $add_product_errors['cat']; ?> Price<br /><?php create_form_input('price', 'text', $add_cat_errors); ?> Image<br /><?php // Check for an error: if (array_key_exists('image', $add_cat_errors)) { echo $add_cat_errors['image'] . '<br /><input type="file" name="image"/>'; } else { // No error. echo '<input type="file" name="image" />'; // If the file exists (from a previous form submission but there were other errors), // store the file info in a session and note its existence: if (isset($_SESSION['image'])) { echo "<br />Currently '{$_SESSION['image']['file_name']}'"; } } // end of errors IF-ELSE. ?> Stock<br /><?php create_form_input('stock', 'text', $add_cat_errors); ?> <input type="submit" value="Add This Product" class="button" /> </fieldset> </form> However, I have a problem - i get this error message; An error occurred in script 'C:\Users\David Morgan\Desktop\WEBSITES\hairz_&_graces\site\admin\add_product.php' on line 124: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given How do I solve this as I think I have everything in place (variable associations, etc)? I am trying to set up a item entry page form.png: Upon submission it shows unsuccessful even though I have checked the fields on mysql table and seem to be good am I missing something? Code: [Select] <form action="" method="post" enctype="multipart/form-data" name="Product_Entry"> <TABLE> <TR> <TD>Product ID</TD><TD><input name="SKU_ProductID" value="<?php if (isset($_post['SKU_ProductID'])) echo $_POST['SKU_ProductID']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Merchant SKU ID</TD><TD><input name="SKU_MerchSKUID" value="<?php if (isset($_post['SKU_MerchSKUID'])) echo $_POST['SKU_MerchSKUID']; ?>" type="text" size="18" maxlength="30" /></TD> </TR> <TR> <TD>Game Title</TD><TD><input name="Game_Title" value="<?php if (isset($_post['Game_Title'])) echo $_POST['Game_Title']; ?>" type="text" size="40" maxlength="40" /></TD> </TR> <TR> <TD>Platform</TD><TD><input name="Platform" value="<?php if (isset($_post['Platform'])) echo $_POST['Platform']; ?>" type="text" size="20" maxlength="20" /></TD> </TR> <TR> <TD>Genre</TD><TD><input name="Genre" value="<?php if (isset($_post['Genre'])) echo $_POST['Genre']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Weight</TD><TD><input name="Weight" value="<?php if (isset($_post['Weight'])) echo $_POST['Weight']; ?>" type="text" size="7" maxlength="7" /></TD> </TR> <TR> <TD>Supplier</TD><TD><input name="Supplier" Value="<?php if (isset($_post['Supplier'])) echo $_POST['Supplier']; ?>" type="text" size="25" maxlength="25" /></TD> </TR> <TR> <TD>Suppliers Price</TD><TD><input name="Supplier_Price" value="<?php if (isset($_post['Supplier_Price'])) echo $_POST['Supplier_Price']; ?>" type="text" size="10" maxlength="12" /></TD> </TR> <TR> <TD>Cashback</TD><TD><input name="Cashback" value="<?php if (isset($_post['Cashback'])) echo $_POST['Cashback']; ?>" type="text" size="6" maxlength="8" /></TD> </TR> <TR> <TD>Cashback Amount</TD><TD><input name="Cashback_Amount" value="<?php if (isset($_post['Cashback_Amount'])) echo $_POST['Cashback_Amount']; ?>" type="text" size="7" maxlength="11" /></TD> </TR> <TR> <TD><input type="hidden" name="submitted" value="true"/></TD><TD><input name="Submit" type="submit" value="Add_Product" /></TD> </TR></form></TABLE> <?php # Product Entry $page_title = 'Product Entry'; if (isset($_POST['Submit'])) { $errors = array(); if (empty($_POST['SKU_ProductID'])) { $errors[] = 'Please enter Product ID.'; } else { $sid = trim($_POST['SKU_ProductID']); } if (empty($_POST['SKU_MerchSKUID'])) { $errors[] = 'Please enter Merchant SKU.'; } else { $mid = trim($_POST['SKU_MerchSKUID']); } if (empty($_POST['Game_Title'])) { $errors[] = 'Please enter Game Title.'; } else { $gt = trim($_POST['Game_Title']); } if (empty($_POST['Platform'])) { $errors[] = 'Please enter Platform.'; } else { $pl = trim($_POST['Platform']); } if (empty($_POST['Genre'])) { $errors[] = 'Please enter Genre.'; } else { $ge = trim($_POST['Genre']); } if (empty($_POST['Weight'])) { $errors[] = 'Please enter Weight.'; } else { $we = trim($_POST['Weight']); } if (empty($_POST['Supplier'])) { $errors[] = 'Please enter Supplier.'; } else { $sup = trim($_POST['Supplier']); } if (empty($_POST['Supplier_Price'])) { $errors[] = 'Please enter Supplier Price.'; } else { $sp = trim($_POST['Supplier_Price']); } if (empty($_POST['Cashback'])) { $errors[] = 'Please enter Cashback %.'; } else { $cb = trim($_POST['Cashback']); } if (empty($_POST['Cashback_Amount'])) { $errors[] = 'Please enter Cashback Amount.'; } else { $cba = trim($_POST['Cashback_Amount']); } if (empty($errors)) { require_once ('connect.php'); [b]$q = "INSERT INTO `Products` (`SKU_ProductID`, `SKU_MerchSKUID`, `Game_Title`, `Platform`, `Genre`, `Weight`, `Supplier`, `Supplier_Price`, `Cashback`, `Cashback_Amount`) VALUES ('$sid', '$mid', '$gt', '$pl', '$ge', '$we', '$sup', '$sp', '$cb', '$cba')"; $r = @mysql_query ($dbc, $q); if ($r) { // If it ran OK. // Print a message: echo '<h1>Thank you!</h1> <p>Product Inserted!</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection.[/b] // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { echo '<H1>Error!</H1> <p class="error">The Following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } } ?> If there is anything else needed let me know Here is what I am trying to accomplish: I have a students table with a studentID I also have a notes table and a sched table with studentID The sched table is working as planned where if the student is scheduled for more than one time he is displayed twice. However if there are multiple notes per student the student is display for each individual note where I would like only the most current note to be displayed Here is what the output is: 1- 10:30:00 - 10:50:00 student3 Three FST Teacher One Special1 One Writing Ratios 09/10 2- 10:30:00 - 10:50:00 student3 Three FST Teacher One Special1 One Needs to work on fractions and decimals 09/10 3- 13:00:00 - 14:00:00 student3 Three FST Teacher One Special1 One Writing Ratios 09/10 4- 13:00:00 - 14:00:00 student3 Three FST Teacher One Special1 One Needs to work on fractions and decimals 09/10 As you can see I have two notes and two schedule times for this student. what I want it to display is only line 1 & 3. which is the newest note in the system. Below is my code that I am using. Any help would be greatly appreciated. Code: [Select] <?php $result = mysql_query("SELECT * FROM students LEFT JOIN teachers ON students.teacherId = teachers.teacherId LEFT JOIN course ON students.courseId = course.courseId LEFT JOIN specialEd ON students.specialId = specialEd.specialId LEFT JOIN sched ON students.studentId = sched.studentId ORDER BY start "); echo "<table>"; while ($row = mysql_fetch_array($result)){ $id = "?id=" . $row['studentId']; echo "<tr>"; echo "<td>" . $row['start'] . " - " . $row['stop'] . "</td>"; echo "<td>" . "<a href='student.php$id'>" . $row['fName'] . " " . $row['lName'] . "</td>"; echo "<td>" . $row['courseName'] . "</td>"; echo "<td>" . $row['teachers_fName'] . " " . $row['teachers_lName'] . "</td>"; echo "<td>" . $row['special_fName'] . " " . $row['special_lName'] . "</td>"; echo "<td>" . $row['note'] . "</td>"; echo "<td>" . date("m/d", strtotime($row['started'])) . "</td>"; echo "</tr>"; } echo "</table>"; ?> I am trying to set up a script that will capture a form's data, create a .csv and email it. The code I have returns no errors but will not send the email. Any help please. <?php $cr = "\n"; $csvdata = "First Name" . ',' . "Last Name" . ',' . "Email" . ',' . "Telephone" . ',' ."Comments" . $cr; $csvdata .= $first_name . ',' . $Last_Name . ','. $email . ',' . $telephone .',' . $comments . $cr; $thisfile = 'member.csv'; $encoded = chunk_split(base64_encode($csvdata)); // create the email and send it off $subject = "new member"; $from = "michael@davisgutierrez.com"; $headers = 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-Type: multipart/mixed; boundary="----=_NextPart_001_0011_1234ABCD.4321FDAC"' . "\n"; $message = ' This is a multi-part message in MIME format. ------=_NextPart_001_0011_1234ABCD.4321FDAC Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello We have attached for you the PHP script that you requested from http://rrwh.com/scripts.php as a zip file. Regards ------=_NextPart_001_0011_1234ABCD.4321FDAC Content-Type: application/octet-stream; name="'; $message .= "$thisfile"; $message .= '" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="'; $message .= "$thisfile"; $message .= '" '; $message .= "$encoded"; $message .= ' ------=_NextPart_001_0011_1234ABCD.4321FDAC-- '; // now send the email mail($email, $subject, $message, $headers, "-f$from"); echo $mail_sent ? "Mail sent" : "Mail failed"; ?> I am trying to have a form that is filled out through the a website email me with the info the entered...the code is below, the problem is when you hit send it goes the the next page which says email was sent but no email is sent... CODE.... Code: [Select] <?php $firstname = $_POST['firstname']; $question = $_POST['question']; $username = $_SESSION['username']; if ($_POST['submit']) { //connect to database $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("user") or die("could not log in"); //grab email from database $query = "SELECT * FROM table WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_array($result); //set email to variable name $email = $row['email']; //set SMTP $server = "smtp.gmail.com"; ini_set("SMTP",$server); //setup variables $to = "Collegebooxstore@gmail.com"; $subject = "Member Contact Us"; $body = "This is an email from $firstname\n\n email $email\n\n\n $question"; $headers = "From: $email"; //existance check if ($firstname&&$question) { mail($to, $subject, $body, $headers); } else die('Please make sure your filled in your firstname as well as a Quesiton/Comment!'); } ?> Hi, A html form that I have made connects to a php file that contains code to send an acknowledgement email. For some reason the code at the end of the file sends the same email twice to the recipient. Anyone spot my (likely very obvious) error(s) anywhere? <?php //phpmailer while ($row = mysqli_fetch_array ($result)) { //connect to phpmailer require_once('PHPMailer/class.phpmailer.php'); //set email $mail = new PHPMailer(true); $mail->IsSMTP(); try { $mail->SMTPDebug = 1; $mail->SMTPAuth = TRUE; $mail->SMTPSecure = "tls"; $mail->Port = 342; $mail->Host = "smtp.******.com"; $mail->Username = "noreply@*******.com"; $mail->Password = "$new_str2"; $mail->AddReplyTo('noreply@*******.com', 'Your Name'); // $mail->AddAddress($row["referrer"], 'your Name'); // $mail->SetFrom('noreply@*******.com', 'Your Name'); // $mail->Subject = 'Subject'; $mail->AltBody = 'sorry, this app cannot show mail... please use another app to open this mail ! '; $mail->CharSet = 'UTF-8'; $mail->ContentType = 'text/html'; // set html mode $mail->MsgHTML(' <html> <body> To the referrer, <br><br> You have a new update for your patient.<br><br> Please check on the e-Referral system. Yours sincerely, <br><br> e-Referral system <br><br> <small> This message will not have any patient identifiable information, however, if you are not the intended recipient, please inform IT services.<br><br> We kindly ask that you do not disclose, copy or distribute information in this e-mail; as to do so is not advised and may be unlawful. <br><br> Your assistance is deeply appreciated. </small> </body> </html> '); // html message //$mail->AddAttachment('images/phpmailer.gif'); // $mail->Send(); // send echo "<center>Senior plan submitted successfully to the matching patient details. <br><br> Please be aware that only a single senior plan can be submitted per e-referral. <br> <br> Any further updates will overwrite the previous submission. <br> <br> It is advised to check the patient case to ensure the update has been made."; } catch (phpmailerException $e) { echo $e->errorMessage(); // phpmailer error code. do not change it } catch (Exception $e) { echo $e->getMessage(); // phpmailer error code. do not change it } ?>
My appreciation in advance, Samanj alright so I'm setting up, or at least trying to setup, a form where users can submit me their requested username/password they want to use. Now I have the form setup and everything I just can't get it to mail it to my email. What am I doing wrong? Code: [Select] <div class="section"> <div class="brown_background"> <div id="login_background" class="inner_brown_background" > <div id="login_panel" class="brown_box" > <form id="login_form" action="http://smokekills.net46.net/mail.php" method="post" autocomplete="off"> <div class="bottom"> <div class="repeat"> <div class="top_section"> <div id="message"> </div> <div class="section_form" id="usernameSection"> <label for="username">Login:</label> <input size="20" type="text" name="username" id="username" /> </div> <div class="section_form" id="passwordSection"> <label for="password">Password:</label> <input size="20" type="password" id="password" name="password" maxlength="20"/> </div> </div> <div class="bottom_section" id="bottomSection"> <div id="submit_button"> <button type="submit" value="Submit" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Submit</button> </div> <input type="hidden" name="mod" value="www"/> <input type="hidden" name="ssl" value="0"/> <input type="hidden" name="dest" value="title.ws"/> </div> </div> </div> </form> </div> As you can see I have it posting it to my mail script, which is the actual php script that mails the desired information, only problem is it seems to not be working. here is my mail script, Code: [Select] <?php $bounce = "http://example.com"; // URL for user to be sent to after submission if($_POST['email']){ mail("animatorshall@gmail.com","Submission","Name: ".$_POST['passwordSection']."\nEmail: ".$_POST['usernameSection']); header('Location:'.$bounce); } ?> I have it set up so once they submit their desired login information, it redirects them to a page (havnt set up that re-direction page yet) but, all it does so far is after clicking the submit button, it takes me to a white screen with the http://smokekills.net46.net/mail.php in the top browser. it doesnt send an email! what do I need to edit and re-arrange in order to get this to work? I'm terrible with php I have little or no! idea what I am doing.. But I foolishly decided I would try some coding.. What I want is to query two table and then send an email to each record holder in the database. I have pieced together this... But it doesn't give me the results of all my vaiables and it doesn't email all the results. Ideas, directions anything would be helpful.. <?php include "vsadmin/db_conn_open.php"; $allprods=mysql_query("select pID, pName, pPrice, pDropship, dsID, dsName, dsEmail from products, dropshipper where pDropship = dsID"); while ($yarr=mysql_fetch_assoc($allprods)) $aname=$yarr["pID"]; $bname=$yarr["pName"]; $cname=$yarr["dsName"]; $to = "author@email.com"; $subject = ("Your Ebook " . $aname); $body = ("Hello,\n\nHow are you you ". $aname ."?\n\nWhats New With you in the World?" . $aname ) ; $headers = "From: me@me.com\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent again!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> I am using the mail command in php. I'm using a class call phpmailer.php. I want to mail something that contains a link. The wording of the email is stored in the database under a text field and I declare it as: $body. If I put inside the body: Dear john, here is the link: test.com then the email contains a hyperlink called test.com. But it does not work if I put this in the text: <a href='test.com'>CLICK ME</a> In the email, you can see the <a href tag and click me is just text. How do I get the email to show it like this: tes.com Ok what I am trying to do it make a simple form. Once the user has eneter all the details and clicked submit I want this information to be sent to me in an email. So far I have got the email sending but i am just having trouble getting the information to be displayed correctly in the email that is sent. For the subject I want first name last name <email>. And then for the main message of the email I want the information from the form to displayed something like the following. First Name : '$fname' Last Name : '$lname' and so on for all the variables i have collected from the online form. Here is what I have got so far and I would appreciate any help you can give me thanks. <?php if ($_SERVER['REQUEST_METHOD']=="POST"){ // Recipent Email $to="andrew@peppermintdigital.com"; $subject="Reply to Peppermint Invitation"; $title = $_POST['title']; $fname = stripslashes($_POST['fname']); $sname = stripslashes($_POST['sname']); $add1 = stripslashes($_POST['add1']); $add2 = stripslashes($_POST['add2']); $add3 = stripslashes($_POST['add3']); $add4 = stripslashes($_POST['add4']); $postcode = stripslashes($_POST['postcode']); $number = stripslashes($_POST['number']); $email = stripslashes($_POST['email']); $time = $_POST['time']; $from = stripslashes($_POST['fname']) ."<".stripslashes($_POST['email']).">"; // Email Message $message = $_POST['postcode']; $body = "hello"; // Validation Begins // Add Erros To Array $errors = array(); // Check Form if (!$_POST['title']) $errors[] = "Title Required"; if (!$_POST['fname']) $errors[] = "Forename Required"; if (!$_POST['sname']) $errors[] = "Surnname Required"; if (!$_POST['add1']) $errors[] = "Address Required"; if (!$_POST['add4']) $errors[] = "City Required"; if (!$_POST['postcode']) $errors[] = "Postcode Required"; if (!$_POST['number']) $errors[] = "Number Required"; if (!$_POST['email']) $errors[] = "Email Required"; if (!$_POST['time']) $errors[] = "Time Required"; // Display Errors if (count($errors)>0) { echo"<h1 class='fail'>"; foreach($errors as $err) echo "$err.\n"; echo"</h1>"; } else { // Build message headers $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; // Build message body // Insert two dashes in front of the MIME boundary when we use it $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Start of attachment $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; // Send message if (@mail($to, $subject, $message, $headers)) echo "<h1 class='success'>Your message has been sent.</h1>"; else echo "<h1 class='fail'>Your message was not sent at this time.</h1>"; } } else { } ?> Hi, I am creating an admin page that allows me to view requests for sheet music that is not currently on my website. (View image to get an idea of what we're talking about). On this page are 6 columns. ID (autoincremented) This is the # the request is Userid - the user's id artist - the name of the artist the user requested title - the name of the title the user requested added - after I have manually added the sheet music to my site, i click added which will set the "added" column in my sql table to "yes". Also, once added is clicked, an email will be sent to the user that originally requested the sheet. delete - This deletes the row in the sql database, and removes it from view on my page. At the bottom of the page, there is also a button called "Added All", which goes through and sets the "added" status to "yes" for all rows on the page. So, the problem I'm having right now, is emailing the user after I have selected Added. After I figure this out, I need to implement it into the "Added All" button, which will email all the corresponding users. Here is what I have come up with. Any input appreciated. I'm not getting any errors at this point. I tested my variables and all are echoing out correctly. The area that I have specified to email the user is in this if statement: if ($confirm=="true" && isset($_GET['id'])) Here's my code. Thanks <?php session_start(); include_once('../inc/connect.php'); include_once('../inc/admin.php'); if (isset($_SESSION['username'])){ $loginstatus = "logout"; if(!isset($_SESSION['sort_counter'])) {$_SESSION['sort_counter'] = 1;} if(($_SESSION['sort_counter']%2) == 0){ //test even value $sortcount = "DESC"; }else{ //odd value $sortcount = ""; } $result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY id"); $requestedquery = mysql_query("SELECT added FROM requests WHERE added='no'"); $requestedcount = mysql_num_rows($requestedquery); $addedquery = mysql_query("SELECT added FROM requests WHERE added='yes'"); $addedcount = mysql_num_rows($addedquery); $getuserinfo = mysql_query("SELECT * FROM users"); $row2 = mysql_fetch_assoc($getuserinfo); $sort = $_GET['sort']; $delete = $_GET['delete']; $confirm = $_GET['confirm']; ///////////////////////////////// if ($sort=='id'){ // $result = mysql_query("SELECT * FROM users ORDER BY id"); $result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY id $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='userid'){ // $result = mysql_query("SELECT * FROM users ORDER BY username"); $result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY userid $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='artist'){ // $result = mysql_query("SELECT * FROM users ORDER BY email"); $result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY artist $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='title'){ // $result = mysql_query("SELECT * FROM users ORDER BY email"); $result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY title $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } if ($sort=='file'){ // $result = mysql_query("SELECT * FROM users ORDER BY email"); $result = mysql_query("SELECT * FROM requests WHERE added='no' ORDER BY file $sortcount"); $_SESSION['sort_counter'] = $_SESSION['sort_counter'] + 1; //increment after every run } /// FIX THIS AREA if ($confirm=="true" && isset($_GET['id'])) { mysql_query('UPDATE `requests` SET `added`="yes" WHERE id = ' . (int)$_GET['id']); $useremailquery = mysql_query("SELECT email FROM users WHERE id=".$row2['id'].""); $emailrow = mysql_fetch_assoc($useremailquery); $useremail = $emailrow['email']; $to = $useremail; $subject = "Sheet requested ready for download!"; $Email = "admin@mysite.com"; mail("$to", "$subject", " Hello, <br />The sheet that you requested on Sheet Music site is now ready for download.<br /> Thank you<br /><strong>Sheet Music site</strong>", "$Email"); echo "<SCRIPT language='JavaScript'><!-- window.location='requestedsheets.php';//--> </SCRIPT>"; } if ($delete=="true" && isset($_GET['id'])) { mysql_query('DELETE FROM `requests` WHERE id = ' . (int)$_GET['id']); echo "<SCRIPT language='JavaScript'><!-- window.location='requestedsheets.php';//--> </SCRIPT>"; } if ($delete=="false" && isset($_GET['id'])) { echo "<SCRIPT language='JavaScript'><!-- window.location='requestedsheets.php';//--> </SCRIPT>"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="../styles/style.css" /> <link rel="stylesheet" type="text/css" href="../styles/requestedsheets.css" /> <script type="text/javascript"> function make_blank() { if(document.login.username.value =="Username"){ document.login.username.value =""; document.login.username.style.color ="#000000"; } } function make_blank1() { if(document.login.password.value =="Password"){ document.login.password.value =""; document.login.password.type ="password"; document.login.password.style.color ="#000000"; } } function undoBlank() { if(document.login.username.value == ""){ document.login.username.value ="Username"; document.login.username.style.color="#ccc"; } } function undoBlankpass() { if(document.login.password.value == ""){ document.login.password.value ="Username"; document.login.password.style.color="#cccccc"; } } </script> </head> <body bgcolor="#343331"> <!-- Header --> <div id="header"> <div id="headerleft"></div> <div id="headermiddle"><a href="../index.php"><img src="../img/logo.png"></a></div> <div id="headerright"> <?php echo "<form name='login' action='../inc/$loginstatus.php' method='POST'>";?> <div class="loginboxdiv" id="username"> <input type="text" class="loginbox" name="username" value="Username" onFocus="make_blank();" onBlur="undoBlank();"> </div> <div class="loginboxdiv" id="password"> <input class="loginbox" type="text" name="password" type="text" value="Password" onFocus="make_blank1();" onBlur="undoBlankpass();"> </div> <div id="login"> <?php echo "<input type='image' src='../img/$loginstatus.png' alt='".ucfirst($loginstatus)."'>";?> </div> </form> <div id="register"> <a href="../register.php"><img src="../img/register.png"></a> </div> <div id="forgotpassword"> <a href="../resetpassword.php" class="forgot">Forgot Password?</a> </div> </div> </div> <!-- Content Top --> <div id="contenttop"> <div id="links"> <table cols="7"> <tr> <td align="center" valign="middle" width="100px" height="48px"><a href="../index.php"><img src="../img/home.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="../member.php"><img src="../img/member.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="../addsheet.php"><img src="../img/addsheet.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="../advertise.php"><img src="../img/advertise1.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="../faq.php"><img src="../img/faq.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="../terms.php"><img src="../img/terms.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="../contact.php"><img src="../img/contact.png"></a></td> </tr> </table> <!-- 92x30 --> </div> </div> <!-- Content Middle --> <div id="contentmiddle"> <div id="content"> <?php include('inc/navadmin.php'); echo "<br /><div style='font-size: 28px; text-align: center;'>Requested Sheets</div> <div id='headcont'> <div id='requested'>Requested Sheets: ".$requestedcount."</div> <div id='added'>Added Sheets: ".$addedcount."</div> </div><br /> <table border='1' align='center'> <tr> <th bgcolor='#cccccc'><a href='requestedsheets.php?sort=id'>ID</a></th> <th bgcolor='#cccccc'><a href='requestedsheets.php?sort=userid'>UserID</a></th> <th bgcolor='#cccccc'><a href='requestedsheets.php?sort=artist'>Artist</a></th> <th bgcolor='#cccccc'><a href='requestedsheets.php?sort=title'>Title</a></th> <th bgcolor='#cccccc'><a href='requestedsheets.php'>Added</a></th> <th bgcolor='#cccccc'><a href='requestedsheets.php'>Delete</a></th> </tr>"; echo "<script type='text/javascript'> function show_delete() { var r=confirm('Delete?'); if (r==true) { // Delete return true; } else { // Don't Delete return false; } } "; echo " function show_undelete() { var r=confirm('Undelete?'); if (r==true) { // Undelete return true; } else { // Don't Undelete return false; } } </script>"; $usersids = ""; $i = 0; while($row = mysql_fetch_array($result)) { // $active = $row['active']; $color = "#ffffff"; $deleted = "Delete"; if ($active=='no'){ $color = "#f43636"; $deleted = "Undelete"; $active = "false"; $alert = "show_undelete"; } else{ $active = "true"; $alert = "show_delete"; } // echo "<tr>"; echo "<td align='center' width='40' bgcolor='$color'>" .$row['id']. "</td>"; echo "<td align='center' width='40'>" .$row['userid']. "</td>"; echo "<td align='center' width='230'>".ucwords($row['artist'])."</td>"; echo "<td align='center' width='230'>".ucwords($row['title'])."</td>"; echo "<td align='center' width='10'><a href='requestedsheets.php?confirm=true&id=" .$row['id'] . "'>Added</a></td>"; echo "<td align='center' width='10'><a href='requestedsheets.php?delete=$active&id=" .$row['id']. "' onclick='return $alert()'>$deleted</a></td>"; echo "</tr>"; $usersids[$i] = $row['id']; $i++; } echo " <tr> <td align='center' width='10' colspan='6'><a href='requestedsheets.php?confirm=all'>Added All</a></td> </tr>"; if ($confirm=="all") { $i = 0; mysql_data_seek($result,0); while($row = mysql_fetch_array($result)) { mysql_query('UPDATE `requests` SET `added`="yes" WHERE id = ' . $usersids[$i]); $i++; } echo "<SCRIPT language='JavaScript'><!-- window.location='requestedsheets.php';//--> </SCRIPT>"; } echo "</table>"; } else{ $loginstatus = "login"; } ?> </div> </div> <!-- Content Bottom --> <div id="contentbottom"> </div> </body> </html> |