Jump to content

barkly

Members
  • Posts

    13
  • Joined

  • Last visited

barkly's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Attitude?? Are you kidding me? I believe you need to look at yourself and read you comments buddy. My second post has the attachment code.... learn to read please. It says, "I'm receiving the emails without an attachment and the email shows me the code instead of the actual email.".... Look for the comment in the code //The Attachment look for it in the second post... You have some issues .. go search for help on google. We are not ALL pros that's why we ask for help here ... if you can't take someone asking for help, maybe go somewhere else where all the other pros go to and see how good you really are. You are nuts dude.
  2. So where is your solution man? Again posting nothing acting like you're a pro. Show us how good you really are. Don't worry about what I'm looking for before inserting that's not the question.... I have my reasons and that's why it's posted. Also READ look at the second code example or are you BLIND? Show us how to insert a CSV in an email with the code provided. Come on since you're a great coder. ... . Do you really think I would name a table thetable???? Dude stick to the issue of attaching a csv and stop wasting everyones time. I'm sure there's many people wondering how to do this and you're asking if I name the table thetable. Is there anyone who could help answer the questions with code example on how to attach a csv after form submission?
  3. It's a scaled down version giving you what you need to help. But since we have a smart-a not a problem. Let's see how good you really are ginerjm, solve the issue. Your little error script which I do use doesn't give me any errors. So come on I challenge you. Figure out why I recieve code emails ... meaning I see the code rather that the images etc. What's your advanced solution?
  4. I tried this code and I'm receiving the emails without an attachment and the email show me the code instead of the actual email. Anyone have any suggestions? <?php $to = "email@email.com"; if(isset($_POST['submit'])) { // VALIDATION if(empty($_POST['firstName'])) { "First Name Required"; } if(empty($_POST['lastName'])) { "Last Name Required"; } if(empty($error)) { $to = "$to"; $subject = 'The Form'; $headers = "MIME-Version: 1.0 \r\n"; $headers .= "Content-Type: text/html; \r\n" ; $msg .="<html> <head></head> <body> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td>This is the email sent.</td></tr> </table> </body> </html>"; include('connection.php'); $con = mysqli_connect($host,$user,$pass,$dbName); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"thetable"); $firstName = mysqli_real_escape_string($con, $_POST['firstName']); $lastName = mysqli_real_escape_string($con, $_POST['lastName']); $sql = "SELECT * FROM thetable WHERE `firstName` = '{$firstName}' OR `lastName` = '{$lastName}'"; $result = mysqli_query($con,$sql); if(($result->num_rows)>= 1) { $theerror = "You exist"; } else { $sql="INSERT INTO thetable(firstName, lastName) VALUES ('$_POST[firstName]','$_POST[lastName]'"; $success = "Sent ... Insert it!!!"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } //The Attachment $cr = "\n"; $data = "Email" . ',' . "First Name" . ',' . "Last Name" . $cr; $data .= "$email" . ',' . "$firstName" . ',' . "$lastName" . $cr; $fp = fopen('diploma_apprenticeship_form_sub.csv','a'); fwrite($fp,$data); fclose($fp); $attachments[] = Array( 'data' => $data, 'name' => 'diploma_apprenticeship_form_sub.csv', 'type' => 'application/vnd.ms-excel' ); //Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; //Add the headers for a file attachment $headers = "MIME-Version: 1.0\n" . "From: {$from}\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; //Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $text . "\n\n"; //Add sttachments foreach($attachments as $attachment){ $data = chunk_split(base64_encode($attachment['data'])); $name = $attachment['name']; $type = $attachment['type']; $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" ; } $message .= "--{$mime_boundary}--\n"; $result = @mail($to, $subject, $msg, $headers, $message); } mysqli_close($con); { } } } ?>
  5. I'm trying to after submission 1. create a csv 2. insert record into db 3. send email that's created in form submission - $msg. 4. send email with attachment to only the email I specify (if possible) if not attach it to the email that's created at submission. I've search and search and found different methods but doesn't work with my code. I kept 3 lines at the top but can't get them to work ... either I don't get an email after submission or don't get an attachement. Can some one help? <?php $random_hash = md5(date('r', time())); $csvString = "..."; // your entire csv as a string $attachment = chunk_split(base64_encode($csvString)); $to = "email@email.com"; if(isset($_POST['submit'])) { // VALIDATION if(empty($_POST['firstName'])) { "First Name Required"; } if(empty($_POST['lastName'])) { "Last Name Required"; } if(empty($error)) { $to = "$to"; $subject = 'The Form'; $headers = "MIME-Version: 1.0 \r\n"; $headers .= "Content-Type: text/html; \r\n" ; $msg .="<html> <head></head> <body> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td>This is the email sent.</td></tr> </table> </body> </html>"; include('con.php'); $con = mysqli_connect($host,$user,$pass,$dbName); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"thetable"); $firstName = mysqli_real_escape_string($con, $_POST['firstName']); $lastName = mysqli_real_escape_string($con, $_POST['lastName']); $sql = "SELECT * FROM thetable WHERE `firstName` = '{$firstName}' OR `lastName` = '{$lastName}'"; $result = mysqli_query($con,$sql); if(($result->num_rows)>= 1) { $theerror = "You exist"; } else { $sql="INSERT INTO thetable(firstName, lastName) VALUES ('$_POST[firstName]','$_POST[lastName]'"; $success = "Sent ... Insert it!!!"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } $result = @mail($to, $subject, $msg, $headers); } mysqli_close($con); { } } } ?>
  6. Thanks for the suggestions. Psycho - You last paragraph I'm not really using message. I used message for posting purposes. Your other suggestions, can you post code so I can follow what you're saying?
  7. I did this to make it work.... come on PHP $message = mysqli_real_escape_string ($con, stripslashes(strip_tags(trim($_POST['message'])))); And this - VALUES mysqli_real_escape_string($message)";
  8. Sorry those were typos I did change the typos and also added - VALUES mysqli_real_escape_string ($_POST['message'])"; but that didn't work. $message= mysqli_real_escape_string($con, $_POST['message']); $sql = "SELECT * FROM table WHERE `message` = '{$message}'"; $result = mysqli_query($sql); if(($result->num_rows)>= 1) { $error = "Message Exists."; } else { $error = "This message does not exist. Insert it!!!"; $sql="INSERT INTO table (message) VALUES mysqli_real_escape_string($_POST['message'])"; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con)
  9. When I add a ' or " quotes in a textarea I get a sql error when it tries to insert the record. I was told to use mysqli_real_escape_string but that didn't work. Here's my code - $blog= mysqli_real_escape_string($con, $_POST['blog']); $blog= $_POST['message']; $sql = "SELECT * FROM table WHERE `message` = '{$message}'"; $result = mysql_query($sql); if ( mysql_num_rows ( $result ) > 0 ) { $error = "Message Exists."; } else { $error = "This message does not exist. Insert it!!!"; $sql="INSERT INTO table (message) VALUES ('$_POST[message])"; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con)
  10. I got it to work. I coded it like `email` = '{$email}' OR `address` = '{$address}'"; I used OR in case one of the two were the same. The other issue I move the db code in a different area. Thanks SocialCloud for your help earlier.
  11. I fixed the email validation issue where it was validating because the address was missing .com but inserting the record anyway. The issues now - 1. If the record exists the error displays but email is sent anyway. 2. When I add address to - $sql = "SELECT * FROM table WHERE (`email` = '{$email}',`address` = '{$address}')"; the data is inserted anyway. Can someone help?
  12. Yes you're right!!! Thank You. I fixed that but now having problems with - $sql = "SELECT * FROM table WHERE `email` = '{$email}'"; I tried 'email' = '{$email}', 'address' = '{$address}'"; but it's inserting when the exact email and address exist. How can I code this to have muliple vars? Also I can enter emal@email and it validates and says it's not correct but it insert the data - the validation works but it doesn't stop the insert.
  13. Hi, I created a form that inserts first - last name, address, and email address into a mysql databse table. The record inserts correctly - No problems here. The problem is I only want to insert the data if the email and address doesn't exist. I set it up for just the email right now to try to get this to work but have failed. When the form is submitted and the record exists it inserts the record anyway and sends the email which it's not suppose to do. The form is suppose to after submitting - 1. validate 2. insert only if the record doesn't exist 3. send the email. Here's the code <?php $to = "email@email.com"; if(isset($_POST['submit'])) { // VALIDATION if(empty($_POST['firstName'])) { $errorfirstName .= "First Name Required"; } if(empty($_POST['lastName'])) { $errorfirstName .= "Last Name Required"; } if(empty($error)) # No error go ahead and email it. { $to = "$to"; $subject = 'the form'; $msg .="<html><head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <title>The Form</title> </head> <body> <table> <tr> <td>Email sent for confirmation</td> </tr> </table> </body> </html>"; $mail($to, $subject, $headers, $msg); if(!$result) { $error = "<div id='errors'>There was an unknown error </div>"; } else { include('connection.php'); $firstName = mysqli_real_escape_string($con, $_POST['firstName']); $lastName = mysqli_real_escape_string($con, $_POST['lastName']); $address = mysqli_real_escape_string($con, $_POST['address']); $email = mysqli_real_escape_string($con, $_POST['email']); $email = $_POST['email']; $sql = "SELECT * FROM table WHERE `email` = '{$email}'"; $result = mysql_query($sql); if ( mysql_num_rows ( $result ) > 0 ) { $error = "Email Exists."; } else { $error = "Email does not exist. Insert it!!!"; $sql="INSERT INTO table (firstName, lastName, address, email) VALUES ('$_POST[firstName]','$_POST[lastName]','$_POST[address]', '$_POST[email]')"; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con) { } } } } ?> <!-- Form --> <html> <head></head> <body> <section> <form method="POST" action="theform" name="for" onsubmit="return validateForm(this)"> <?php if(!empty($error)) { echo "$error"; } ?> This where the inputs would go not going to include them because not having an issue with the form </form> </section> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.