prova17
New Members-
Posts
9 -
Joined
-
Last visited
prova17's Achievements
Newbie (1/5)
0
Reputation
-
Good morning! I have an html form where people should insert the information and then send 2 attachments to a specific email. The following code works but in the attachment of the email I find the name like this --> /tmp/phpJih9x2. Somebody could help me? Following I attach the HTML and PHP file! THANKS HTML <form id="form1" name="form1" method="post" action="email2.php" enctype="multipart/form-data"> <fieldset> <legend>Canditatura</legend> <label>Nome:</label> <input type="text" placeholder="Inserisci il tuo nome" name="nome" size="30px" required="true"><br> <label>Cognome:</label> <input type="text" placeholder="Inserisci il tuo cognome" name="cognome" size="30px" required="true"><br> <label>Email:</label> <input type="email" name="email" placeholder="example@example.it" size="30px" required="true"><br> <label>Telefono:</label> <input type="tel" name="telefono" placeholder="+39" size="30px"><br> <label>Allegato 1:</label> <input type="file" id="allegato" name="allegato" required="true"><br> <label>Allegato 2:</label> <input type="file" id="allegato2" name="allegato2" required="true"><br> <br><br> <label class="lprivacy"><input type="checkbox" required="true">Accetto normativa sulla Privacy</label><input type="submit" value="Invia Canditatura" name="submit"> </fieldset> </form> PHP <?php $allegato = $_FILES['allegato']['tmp_name']; $allegato_type = $_FILES['allegato']['type']; $allegato_name = $_FILES['allegato']['name']; $allegato2 = $_FILES['allegato2']['tmp_name']; $allegato2_type = $_FILES['allegato2']['type']; $allegato2_name = $_FILES['allegato2']['name']; $email = $_POST['email']; $nome = $_POST['nome']; $cognome = $_POST['cognome']; $telefono = $_POST['telefono']; mail_attachment("myemail@mysite.com","Subject","Nuova canditatuda da <b>$nome $cognome</b>. <br> Telefono: $telefono <br> Email: $email ",array("$allegato","$allegato2")); function mail_attachment($to, $subject, $message, $files) { $headers = "From: no-reply@mail.com"; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $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" . $message . "\n\n"; $message .= "--{$mime_boundary}\n"; foreach ($files as $file) { $filename = end(explode("/",$file)); $data = file_get_contents($file); $data = chunk_split(base64_encode($data)); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$file\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$file\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $message .= "--{$mime_boundary}\n"; } echo (@mail($to, $subject, $message, $headers)) ? "<p>Messaggio spedito correttamente a $to!</p>" : "<p>ERRORE! Messaggio non spedito a $to!</p>"; } // mail-attachment ?>
-
Thanks alpine for the advice, unfortunately I'm not really an expert and I'm trying to learn as I can by forum and internet. Hope what I did isn't included in "best practise" for an application using JQM and phonegap. I installed in a mobile device and it work perfectly, I'm just scared it will be slow in the future when there will be more data in the db, unfortunately I can't change the db settings. Thank you!
-
Thanks for the advice but I tryed as you said and it doesn't work. I have a question, is it incorrect use this code? $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'")); About the HTML markup in the DB don't ask me why but I'm getting data from a CMS and save the HTML markup in the description. I solved the problem in the js file using "html" insted "text". function displayEmployee(data) { var employee = data.item; console.log(employee); $('#employeePic').attr('src', 'img/' + employee.img); $('#employeeTitle').text(employee.title); $('#description').html(employee.description); Thanks!
-
I found a solution I added --> array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'") and now it works $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'")); Now I have only a problem...When I see the description of the review book I see all the HTML tags (<p style="text-align: justify;">Trovarsi a leggere un libro noir scritto....) How can I avoid it? Really thanks for all the people helped me!!
-
I found a solution but I don't if it is the best. I replace the special characters by SELECT REPLACE directly on the query. $sql = "SELECT REPLACE(title, 'ò', 'ò') as title, id, description, img, info1 FROM table_books WHERE info5 = 'thriller' ORDER BY id DESC"; Is it a good solution or not? thank you!
-
No way! Do you have another exaple to insert in my code? Thanks!!! P.S.: I'm not an expert and maybe I'm doing something wrong, if is possible insert examples in my code Really Thanks
-
Thanks! I'm sorry I'm not an expert but my string should be this $employees = $stmt->fetchAll(PDO::FETCH_OBJ); ?
-
Thanks for help! I tryed to insert the utf8_encode but I obtain the result "Undefined". try { $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->query($sql); $employees = $stmt->fetchAll(PDO::FETCH_OBJ); $dbh = null; echo '{"items":'. json_encode(utf8_encode($employees)) .'}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } If you need there is the .js file. var serviceURL = "/services/"; var employees; $(document).ready (function() { getEmployeeList(); }); $(document).delegate('#employeeListPage','pageshow', function(event) { getEmployeeList(); }); $('#employeeListPage').bind('pageinit', function(event) { getEmployeeList(); }); function getEmployeeList() { $.getJSON(serviceURL + 'getemployees.php', function(data) { $('#employeeList li').remove(); employees = data.items; $.each(employees, function(index, employee) { $('#employeeList').append('<li><a href="employeedetails.html?id=' + employee.id + '">' + '<img src="img/' + employee.img + '" width="80px" height="80px" />' + '<h4>' + employee.title + '</h4>' + '<p>' + employee.info1 + '</p>' + '</a></li>'); }); $('#employeeList').listview('refresh'); }); } Somebody could help me? Thanks!
-
Good evening! I'm new in the forum and programming php! I'm trying to create an application with jqmobile. From the following I obtain results from db mysql but I obtain value "null" when there are special characters like ò, à, è, ù ... Is it possible to replace the special characters? THANKS!!! <?php include 'config.php'; $sql = "SELECT * FROM table_books WHERE info5 = 'thriller' ORDER BY id DESC"; try { $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->query($sql); $employees = $stmt->fetchAll(PDO::FETCH_OBJ); $dbh = null; echo '{"items":'. json_encode($employees) .'}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } ?>