Visualizzazione risultati 1 fino 12 di 12

Discussione: inviare email da php

  1. #1
    Guest

    Predefinito inviare email da php

    ciao a tutti ho un problema con uno script per inviare le email da php
    Codice PHP:
    <?php
    // read the list of emails from the file.
    $email_list = file("elist.txt");

    // 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);

    $subject = "My email test.";
    $message = "Hello, how are you?";

    if (
    mail($to,$subject,$message) ) {
    echo
    "The email has been sent!";
    } else {
    echo
    "The email has failed!";
    }
    ?>
    il codice prende gli indirizzi email dal file elist.txt e fin qui tutto ok solo che li manda con mittente anonimo, come faccio ad inserire un mittente personalizzato?
    grazie mille
    Ultima modifica di sabbadini : 26-05-2011 alle ore 17.54.37 Motivo: errori grammaticali

  2. #2
    Guest

    Predefinito

    Codice PHP:
    $headers = "From: inidirizzoemail(a)dominio.it";

    mail($to,$subject,$message, $headers)

  3. #3
    karl94 non è connesso Staff AV
    Data registrazione
    03-10-2005
    Messaggi
    17,744

    Predefinito

    Devi passare alla funzione mail un quarto parametro, una stringa contenente i vari header aggiuntivi. L'header per specificare il mittente è generalmente così:
    Codice:
    From: "Nome del mittente" <email@mittente>
    Ultima modifica di karl94 : 26-05-2011 alle ore 18.08.38

  4. #4
    L'avatar di EuroSalute
    EuroSalute non è connesso AlterVistiano
    Data registrazione
    12-05-2003
    Messaggi
    969

    Predefinito

    Codice PHP:
    $from="la_tua_email@altervista.org";

    $headers = "MIME-Version: 1.0\r\n" ;
    $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
    $headers .= "Content-Transfer-Encoding: 8bit\r\n";
    $headers .= "From: ".$from."\r\n";

    if (
    mail($to,$subject,$message,$headers) ) {
    echo
    "The email has been sent!";
    } else {
    echo
    "The email has failed!";
    }
    LOTTO MATEMATICO-SCENTIFICO che FUNZIONA:
    Scripts di Calcolo Automatico Metodologie http://eurosalute.altervista.org

    VINCI OGNI SETTIMANA CON IL NUOVO METODO 5
    FAI IL TEST CON L'ANALISI VINCITE

  5. #5
    Guest

    Predefinito

    grazie a tutti ora sono fuori casa appena rientro li provo e vi faccio sapere.
    ciao

    ragazzi ho provato tutti i 3 codici ma continua a mandarmeli anonimamente, non è che qualcuno puoi scrivermi tutto il codice completo della pagina?
    grazie
    ciao
    Ultima modifica di karl94 : 26-05-2011 alle ore 20.37.32

  6. #6
    karl94 non è connesso Staff AV
    Data registrazione
    03-10-2005
    Messaggi
    17,744

    Predefinito

    Puoi indicare tu il codice che stai provando?

  7. #7
    Guest

    Predefinito

    Codice PHP:
    <?php
    // read the list of emails from the file.
    $email_list = file("elist.txt");

    // 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);

    $subject = "My email test.";
    $message = "Hello, how are you?";
    $headers = "From: tuamail(a)dominio.it";

    if (
    mail($to,$subject,$message,$headers) ) {
    echo
    "The email has been sent!";
    } else {
    echo
    "The email has failed!";
    }
    ?>
    Questo è il codice completo (Al massimp postiamo tutti e 3 i tentativi), se non funziona come ha detto karl (scusa se scrivo ora ma la tua risposta è apparsa ora) indica che codice hai provato..

  8. #8
    Guest

    Predefinito

    Codice PHP:
    <?php
    // read the list of emails from the file.
    $email_list = file("elist.txt");

    // 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);

    $subject = "My email test.";
    $message = "Hello, how are you?";
    $headers = "From: tuamail(a)dominio.it";

    if (
    mail($to,$subject,$message,$headers) ) {
    echo
    "The email has been sent!";
    } else {
    echo
    "The email has failed!";
    }
    ?>
    ovviamente adesso ho inserito un indirizzo email finto e continuano ad arrivarmi anonime
    Ultima modifica di sabbadini : 26-05-2011 alle ore 20.43.16

  9. #9
    karl94 non è connesso Staff AV
    Data registrazione
    03-10-2005
    Messaggi
    17,744

    Predefinito

    Ho provato il codice e funziona correttamente.

  10. #10
    L'avatar di EuroSalute
    EuroSalute non è connesso AlterVistiano
    Data registrazione
    12-05-2003
    Messaggi
    969

    Predefinito

    non è che l'errore è nel tuo file elist.txt....

    prova semplicemente a inviarti (a te stesso) una mail, così:
    Codice PHP:
    $subject = "Prova Invio Mail!";
    $body = " - Indirizzo IP: ".getenv("REMOTE_ADDRESS")."
    - Agent: "
    .getenv("HTTP_USER_AGENT")."";

    $emailto = "IL_TUO_NICK@altervista.org";
    $headers = "From: $emailto";

    @
    mail($emailto, $subject, $body, $headers);
    LOTTO MATEMATICO-SCENTIFICO che FUNZIONA:
    Scripts di Calcolo Automatico Metodologie http://eurosalute.altervista.org

    VINCI OGNI SETTIMANA CON IL NUOVO METODO 5
    FAI IL TEST CON L'ANALISI VINCITE

  11. #11
    Guest

    Predefinito

    Una cosa.. spero che tu abbia sostituito (a) con @ .. Tanto per esser sicuri, se l' hai fatto prova come ha detto salute

  12. #12
    Guest

    Predefinito

    ciao grazie a tutti, ora funziona, non so cosa ho fatto ma ora va grazie mille

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •