Jump to content

Enviar mail a utilizadores inscritos numa base de dados


JDrEd
 Share

Recommended Posts

Boas, sei pouco de php e tenho andado a tentar fazer uma mail lista, a inscrição dos utilizadores, administração destes já fiz e está tudo ok 🙂

Agora falta fazer um php para ir a base de dados buscar os vários mails dos utilizadores e enviar um mail definido por mim para estes.

Tentei fazer o que vou postar abaixo, mas está a dar uma série de erros.

Estrutura da base de dados

CREATE TABLE noticias (
id int(5) NOT NULL auto_increment,
nome char(30) NOT NULL ,
email char(80) ,
data date NOT NULL,
hora time NOT NULL ,
ver char(3) DEFAULT 'off' ,
PRIMARY KEY (id),
UNIQUE id (id)
);

O ver fica por default off, e depois é modificado por mim (como que uma aceitação do registo), agora queria mandar um mail para todos os utilizadores registados na bd e que o ver estive-se on.

Isto foi o que fiz  😄

<html>
<head>
<title>Formulario de E-mail</title>
</head>
<body>
<table width="80%" align="center">
<form action="mail.php" method="post" name="formulario" id="formulario">
<tr>
<td width="20%">Seu Email</td>
<td><input type="text" name="meu" size="50" maxlength="255"></td>
</tr>
<tr>
<td width="20%">Assunto</td>
<td><input type="text" name="titulo" size="50" maxlength="255"></td>
</tr>
<tr>
<td colspan=2>Sua Mensagem<br>
<textarea cols="53" rows="5" name="texto"></textarea>
</td>
</tr>
<tr>
<td colspan=2 align="center"><input type="submit" value="Enviar Email"></td> 
</tr>
</form>

</table>

</body>
</html>

<?php

$conexao = mysql_connect("localhost","XXXX","XXX");
$db = mysql_select_db("ciaia_ciaia");
$sql = "SELECT * FROM newsletter WHERE e='$id'";
$resultado = mysql_query($sql)
or die ("Não foi possível realizar a consulta ao banco de dados");

while ($linha=mysql_fetch_array($resultado)) {
$email = $linha["email"];

$destino = $email;
$rementente = $meu;
$assunto = $titulo;
$mensagem= $texto;

$headers = "Content-Type: text/html; charset=iso-8859-1"; 
$headers.="From:".$rementente.""; 

mail("$destino", "$assunto", "$mensagem","$headers"); 

?>

Desculpem lá os erros :S

Se me pudessem dar uma ajuda agradecia

Grande Abraço

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.