Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Probblemi Mail Attach

  1. #1

    Probblemi Mail Attach

    Ciao a tutti.
    Grazie anticipatamente...
    Sto' provando a mandare e-mail con PHP
    tutto funge...+- ovvero mando mail con attach da Web,
    arriva l'e-mail... ma... L'allegato è corrotto.. o danneggiato.
    Ho provato ad allegare diversi files... ma nada...
    Il Codice usato è il seguente :

    <?php

    // RENDIAMO LO SCRIPT COMPATIBILE CON LE VERSIONI DI PHP < 4.1.0
    if(!isset($_POST)) $_POST = $HTTP_POST_VARS;
    if(!isset($_FILES)) $_FILES = $HTTP_POST_FILES;

    // RIPULIAMO I VARI CAMPI DEL MODULO
    $Destinatario = trim($_POST["Destinatario"]);
    $Soggetto = trim(stripslashes($_POST["Soggetto"]));
    $Contenuto = trim(stripslashes($_POST["Contenuto"]));

    // ASSEGNIAMO A VARIABILI PIU' LEGGIBILI, LE PROPRIETA' DELL'ALLEGATO
    $attach = $_FILES["allegato"]["tmp_name"];
    $file_name = $_FILES["allegato"]["name"];
    $file_type = $_FILES["allegato"]["type"];
    $file_size = $_FILES["allegato"]["size"];

    // DELIMITATORE
    $boundary = md5(uniqid(microtime()));

    // APRIAMO L'ALLEGATO PER LEGGERLO E CODIFICARLO
    $file = @fopen($attach, "r");
    $contents = @fread($file, $file_size);
    $encoded_attach = chunk_split(base64_encode($contents));

    @fclose($file);

    // INTESTAZIONI DELLA MAIL
    $mail_headers .= "MIME-version: 1.0\n";
    $mail_headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"";
    $mail_headers .= "X-attachments: $file_name\n";

    // COSTRUIAMO IL CORPO DELLA MAIL
    $mail_body = "--$boundary\n";
    $mail_body .= "Content-Type: text/plain; charset=us-ascii\n";
    $mail_body .= "Content-Transfer-Encoding: 7bit\n\n";
    $mail_body .= "$Contenuto\n\n";
    $mail_body .= "--$boundary\n";
    $mail_body .= "Content-type: $file_type; name=\"$file_name\"\n";
    $mail_body .= "Content-Transfer-Encoding: base64\n";
    $mail_body .= "$encoded_attach\n";
    $mail_body .= "--$boundary--\n";

    // INVIO DELLA MAIL
    if(@mail($Destinatario, $Soggetto, $mail_body, $mail_headers)) { // SE L'INVIO E' ANDATO A BUON FINE...
    echo "Dest $Destinatario";
    echo "La mail è stata inoltrata con successo.";


    } else {// ALTRIMENTI...

    echo "Si sono verificati dei problemi nell'invio della mail.";

    }

    ?>
    shd

  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2002
    Messaggi
    443
    Usa la classe phpmailer

    http://phpmailer.sourceforge.net/

  3. #3

    rr..

    Innanzi tutto grazie.
    ma come si fà ad integrare una classe in Php ?
    Hai un esempio di utilizzo di questa classe x Inviare mail con attach?
    Grazie.
    shd

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2002
    Messaggi
    443
    Codice PHP:
    require_once($_SERVER['DOCUMENT_ROOT'].'/includes/phpmailer/class.phpmailer.php');


    $mail = new phpmailer();
    $mail->From     $_POST['email'];
    $mail->FromName $_POST['name'];
    $mail->Subject  $_POST['subject'];
    $mail->Mailer   "smtp";
    $mail->IsHTML(true);


    // HTML body
    $body "contenuto della mail in formato HTML";
    $mail->Body    $body;

    // TEXT body
    $text_body  "contenuto della mail in formato TESTO" ;
    $mail->Body    $text_body;

    $mail->AddAddress("email@dominio.ext""per il sig. Rossi");

    if(!
    $mail->Send())
    {
         echo 
    "Non riesco a spedire l'email a [email]email@dominio.ext[/email]
    "
    ;


  5. #5

    rr.

    Ciao. Grazie x RR...
    Senti ho provato seguente cod.. :
    Sul mio Pc Funge.. Sul Server Internet di Aruba... va in panna con messaggio :
    "Message could not be sent.
    Mailer Error: Language string failed to load: recipients_failedinfo@italy-tech.com"

    Hai qualche idea ?

    Codice :
    <?php
    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = "relay.albacom.net;mail.tim.it"; // specify main and backup server
    $mail->SMTPAuth = false;
    //$mail->SMTPAuth = true; // turn on SMTP authentication
    //$mail->Username = "jswan"; // SMTP username
    //$mail->Password = "secret"; // SMTP password

    $mail->From = "bacobas@libero.com";
    $mail->FromName = "Mailer Bacobas";
    //$mail->AddAddress("info@italy-tech.com", "Information");
    $mail->AddAddress("info@italy-tech.com");
    //$mail->AddAddress("bassignana.e@italy-tech.com","Bassi"); // name is optional
    $mail->AddReplyTo("itr@italy-tech.com", "ITR");

    $mail->WordWrap = 50; // set word wrap to 50 characters
    $mail->AddAttachment("1.jpg"); // add attachments
    $mail->AddAttachment("2.jpg", "new.jpg"); // optional name
    $mail->IsHTML(true); // set email format to HTML

    $mail->Subject = "Here is the subject";
    $mail->Body = "This is the HTML message body in bold!";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";

    if(!$mail->Send())
    {
    echo "Message could not be sent.

    ";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
    }

    echo "Message has been sent";
    ?>
    shd

  6. #6

    rr...

    Ok Grazie cmq!
    Risolto!
    L'smtp di Aruba.. chiaramente non è il mio ==>
    Non fungeva!!!
    Grazie x gli aiuti e le dritte!
    shd

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.