-
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
-
Codice PHP:
$headers = "From: inidirizzoemail(a)dominio.it";
mail($to,$subject,$message, $headers)
-
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>
-
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!";
}
-
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
-
Puoi indicare tu il codice che stai provando?
-
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..
-
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
-
Ho provato il codice e funziona correttamente.
-
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);
-
Una cosa.. spero che tu abbia sostituito (a) con @ .. Tanto per esser sicuri, se l' hai fatto prova come ha detto salute
-
ciao grazie a tutti, ora funziona, non so cosa ho fatto ma ora va grazie mille