Beh ci sono alcune cose da dire
innanzitutto controllare sempre la documentazione relativa alle funzioni usate :
Funzione mail(...)
Poi il messaggio lo carichi cosi0:
$msg .= "Oggetto: $oggettotxt\n\n";
$msg .= "Messaggio: $messaggiotxt\n\n";
Ma non cofiguri da nessuna parte le variabili $oggettotxt ne $messaggiotxt. Per cui non contengono nulla.
Tali variabili devi configurarle in base a dove si trovano i dati. Se li hai messi in form devi fare come ha detto mrclick ossi caricarli da $_POS/$_GET['nome_campo'].
Inoltre non cofiguri nessn header per la mail e il messaggio arrivera' in plain text a patto che il ricevente lo accetti.
TI consiglio vivamente di impostare un header per l'invio della mail.
Eventualmente ti fai una funzione tipo
Codice PHP:
/*
options => array delle opzioni
addr -> destinatario
sbj -> subject
msg -> messaggio
*/
function myMailer( options )
{
$addr = $options[addr];
$sbj = $options[sbj];
$msg = str_replace( array("\n") , array("
" , $options[msg] );
/*Controllo base sintassi indirizzo mail inserito*/
if( !filter_var($addr, FILTER_VALIDATE_EMAIL) )
return false;
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: $addr <$addr>' . "\r\n";
$headers .= 'From: NEWSLETTER <mydomain@example.com>' . "\r\n";
// Mail it
if( @mail($addr, $sbj, $msg, $headers))
return true;
else
return false;
}
poi puoi usare tale funzione per inviare le email a patto che carichi correttamente i dati.
ad esempio poniamo caso che fai un form tipo
<form name="newsletter" action="newsletter_sender.php" method="post">
mail :<input type="text" name="mail">
subject :<input type="text" name="sbj">
message :<textarea name="msgl"></textarea>
<input type="submit" value="Invia newsletter">
</form>
Nel php newsletter_sender.php farai
Codice PHP:
<?
// mi collego al database
$host = 'sql.xxxx.com';
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$dbname = 'xxxx';
$table = 'news';
$db = @mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
$db = mysql_select_db($dbname);
//////////////////////////////
$query = "SELECT * FROM news WHERE email != ''";
$result = mysql_query($query);
$options = array();
while($m = mysql_fetch_array($result))
{
$options[addr] = $_POST[addr] ;
$options[sbj] = $_POST[sbj];
$options[msg] = $_POST[msg];
echo $m['email'].'
';
if(myMailer($options))
echo " Mail inviata ".$m[email]."
";
else
echo " Invio fallito ".$m[email]."
";
}
?>
Con una cosa del genere poi inviare la mail ai avari destinatari con tanto di header etc etc