ivan919 Posted June 25, 2012 at 09:37 AM Report Share #465317 Posted June 25, 2012 at 09:37 AM (edited) Boas, Um dos projectos que tenho que fazer no estágio é um script que vá à base de dados e envie emails para todos os contactos de uma tabela. Mas ainda nem a parte de enviar email consegui fazer... Até agora tenho: <html> <head> </head> <body> <form action="email.php" method="post"> from:<input type="text" name="from"><br> pass:<input type="password" name="pass"><br><br> To:<input type="text" name="to"><br> Subject: <input type="text" name="subject"><br> Message:<br> <textarea name="message" rows="10"> <textarea> <input type="submit" value="Submit"> </form> </body> </html> <?php $to= $_POST["to"]; $subject= $_POST["subject"]; $body= $_POST["message"]; $header = $_POST["from"]; if(mail($to, $subject, $body, $header)) { echo("Mensagem enviada!"); } else { echo("Erro"); } ?> Preciso ainda fazer a autenticação mas não sei como :X Quando tento enviar assim o email aparece o erro: Warning: mail() [function.mail]: SMTP server response: 503 No valid recipients specified. in C:\xampp\htdocs\www\email.php on line 7 Erro Alguém me consegue explicar como fazer a autenticação? e se esse erro ocorre mesmo por nao haver essa autenticação ou se tenho que configurar alguma coisa? Tenho o XAMPP instalado no computador e pelo que percebi é o Mercury que trata dessas coisas de email. Edited June 25, 2012 at 10:21 AM by ivan919 O geshi do HTML estava errado Link to comment Share on other sites More sharing options...
PF2G Posted June 25, 2012 at 11:07 AM Report Share #465333 Posted June 25, 2012 at 11:07 AM No teu botao da um nome: <input type="submit" value="Submit" name="submit"> depois faz um if(isset($_POST['submit'])) { //o teu codigo } else { echo 'Erro!!!'; } Espero ter ajudado. 🙂 Link to comment Share on other sites More sharing options...
ivan919 Posted June 25, 2012 at 11:18 AM Author Report Share #465335 Posted June 25, 2012 at 11:18 AM (edited) No teu botao da um nome: <input type="submit" value="Submit" name="submit"> depois faz um if(isset($_POST['submit'])) { //o teu codigo } else { echo 'Erro!!!'; } Espero ter ajudado. 🙂 alterei o codigo como disseste mas a unica coisa que alterou foi: em vez de aparecer aquele erro que aparecia antes aparece a mensagem "Erro!!!" Mas ainda nao envia emails :X <?php if(isset($_POST['submit'])) { $to= $_POST["to"]; $subject= $_POST["subject"]; $body= $_POST["message"]; $header =$_POST["from"]"; if(mail($to, $subject, $body, $header)) { echo("Mensagem enviada!"); } else { echo("Erro"); } } else { echo 'Erro!'; } ?> EDIT: agora o erro que aparece é: Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\www\email.php on line 8 Erro Edited June 25, 2012 at 11:22 AM by ivan919 Link to comment Share on other sites More sharing options...
MASNathan Posted June 25, 2012 at 11:28 AM Report Share #465336 Posted June 25, 2012 at 11:28 AM (edited) ... Edited June 26, 2012 at 08:37 AM by MASNathan Link to comment Share on other sites More sharing options...
PF2G Posted June 25, 2012 at 11:30 AM Report Share #465337 Posted June 25, 2012 at 11:30 AM alterei o codigo como disseste mas a unica coisa que alterou foi: em vez de aparecer aquele erro que aparecia antes aparece a mensagem "Erro!!!" Mas ainda nao envia emails :X <?php if(isset($_POST['submit'])) { $to= $_POST["to"]; $subject= $_POST["subject"]; $body= $_POST["message"]; $header =$_POST["from"]"; if(mail($to, $subject, $body, $header)) { echo("Mensagem enviada!"); } else { echo("Erro"); } } else { echo 'Erro!'; } ?> EDIT: agora o erro que aparece é: Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\www\email.php on line 8 Erro Não tenho a certeza que te resolva, mas exeperimenta substituir o teu header por isto: $headers = 'From: $emil . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); Link to comment Share on other sites More sharing options...
ivan919 Posted June 25, 2012 at 11:48 AM Author Report Share #465339 Posted June 25, 2012 at 11:48 AM o problema é no HTML como tu tens: <input type="text" name="from"> como deve ser: <input type="text" name="from"/> espero ter ajudado Cumps... Fiz isso mas o problema continuou... Não tenho a certeza que te resolva, mas exeperimenta substituir o teu header por isto: $headers = 'From: $emil . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); ao codigo que me deste fiz as seguintes alteraçoes: $header = 'From: xxxxxxxxxx@hotmail.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); o xxxxxxxxx@hotmail.com é o meu email pessoal, dai estar agora com xxxxxxxx. Só nao percebi para que serve o 'Reply-To: webmaster@example.com' . "\r\n" . E continua sem funcionar e a dar este erro: Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\xampp\htdocs\www\email.php on line 10 Erro Link to comment Share on other sites More sharing options...
PF2G Posted June 25, 2012 at 01:18 PM Report Share #465351 Posted June 25, 2012 at 01:18 PM Fiz isso mas o problema continuou... ao codigo que me deste fiz as seguintes alteraçoes: $header = 'From: xxxxxxxxxx@hotmail.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); o xxxxxxxxx@hotmail.com é o meu email pessoal, dai estar agora com xxxxxxxx. Só nao percebi para que serve o 'Reply-To: webmaster@example.com' . "\r\n" . E continua sem funcionar e a dar este erro: Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\xampp\htdocs\www\email.php on line 10 Erro Estranho.. Eu uso sempre este codigo: //e-mail que receberá a mensagem $para = "*******@hotmail.com"; $assunto = "Contacte-nos - Escola de Música de V.N.Gaia"; if (isset($_REQUEST['email'])) { //informação preenchida $nome = $_REQUEST['nome']; $mensagem = $_REQUEST['mensagem']; $email = $_REQUEST['email']; echo $nome; //cabeçalho $headers = "MIME-Version: 1.1\r\n"; $headers .= "Content-type: text/plain; charset=UTF-8\r\n"; $headers .= "From: '" . $nome . "'\r\n"; // remetente $headers .= "Return-Path: " . $para . "\r\n"; // return-path //envio do email if(mail($para, $assunto, $mensagem, $headers)) { echo "<script> alert('Mensagem enviada com sucesso. Obrigado!!'); location.href='index.php'; </script>"; } else { echo "<script> alert('Mensagem não foi enviada. Tente mais tarde.'); location.href='contact.php'; </script>"; } } Depois manda feedback... Link to comment Share on other sites More sharing options...
ivan919 Posted June 25, 2012 at 01:54 PM Author Report Share #465355 Posted June 25, 2012 at 01:54 PM PF2G estou a testar o teu codigo mas ainda nao consegui... Tenho uma duvida... antes de enviarmos o email é preciso verificar se o email e a password estao certas não é? e só depois de confirmado é que irá dar para fazer o envio do email... Estou a seguir a teoria do hotmail... primeiro temos que fazer o login e so depois conseguimos enviar o email Link to comment Share on other sites More sharing options...
PF2G Posted June 25, 2012 at 02:02 PM Report Share #465358 Posted June 25, 2012 at 02:02 PM PF2G estou a testar o teu codigo mas ainda nao consegui... Tenho uma duvida... antes de enviarmos o email é preciso verificar se o email e a password estao certas não é? e só depois de confirmado é que irá dar para fazer o envio do email... Estou a seguir a teoria do hotmail... primeiro temos que fazer o login e so depois conseguimos enviar o email ah estas a fazer um sistema tipo hotmail? assim sim, tens de fazer um sistema de login e depois um session_start, depois o user estiver logado, o botao 'enviar' fica normal, se não estiver logado o botao fica disabled. O código que puseste la em cima é o teu codigo completo? Se for ainda tens muita coisa pa fazer... Link to comment Share on other sites More sharing options...
ivan919 Posted June 25, 2012 at 02:12 PM Author Report Share #465362 Posted June 25, 2012 at 02:12 PM ah estas a fazer um sistema tipo hotmail? assim sim, tens de fazer um sistema de login e depois um session_start, depois o user estiver logado, o botao 'enviar' fica normal, se não estiver logado o botao fica disabled. O código que puseste la em cima é o teu codigo completo? Se for ainda tens muita coisa pa fazer... Bem o que me mandaram fazer foi: pegar numa tabela de uma bd com emails, e enviar para eles um email... Eu tava a tentar primeiro enviar um email com um form e so depois passar para a base de dados... Mas da para enviar email sem fazer um sistema de login? Link to comment Share on other sites More sharing options...
PF2G Posted June 25, 2012 at 02:24 PM Report Share #465368 Posted June 25, 2012 at 02:24 PM Bem o que me mandaram fazer foi: pegar numa tabela de uma bd com emails, e enviar para eles um email... Eu tava a tentar primeiro enviar um email com um form e so depois passar para a base de dados... Mas da para enviar email sem fazer um sistema de login? Entao espera aí eles têm uma Tabela com uma lista de emails e enviar um email cujo destinatário é essa lista? Por enquanto esquece o sistem de login... Link to comment Share on other sites More sharing options...
ivan919 Posted June 25, 2012 at 02:30 PM Author Report Share #465371 Posted June 25, 2012 at 02:30 PM id nome email 1 a a@hotmail.com 2 b b@hotmail.com 3 c c@hotmail.com 4 d d@hotmail.com imaginemos que tenho esta tabela... e preciso de mandar um email a informar essas pessoas de algo... é isso apenas, poder escrever a mensagem e enviar para todos os contactos dessa tabela... Mas queria começar pelo mais básico também para perceber bem esta materia... Link to comment Share on other sites More sharing options...
PF2G Posted June 25, 2012 at 02:35 PM Report Share #465372 Posted June 25, 2012 at 02:35 PM Também tenho este //e-mail que receberá a mensagem $para = "*****@hotmail.com"; $assunto = "Assunto"; if (isset($_REQUEST['email'])) { //informação preenchida $nome = $_REQUEST['nome']; $mensagem = $_REQUEST['mensagem']; $email = $_REQUEST['email']; echo $nome; //cabeçalho $headers = "MIME-Version: 1.1\r\n"; $headers .= "Content-type: text/plain; charset=UTF-8\r\n"; $headers .= "From: '" . $nome . "'\r\n"; // remetente $headers .= "Return-Path: " . $para . "\r\n"; // return-path //envio do email if(mail($para, $assunto, $mensagem, $headers)) { echo "<script> alert('Mensagem enviada com sucesso. Obrigado!!'); location.href='index.php'; </script>"; } else { echo "<script> alert('Mensagem não foi enviada. Tente mais tarde.'); location.href='contact.php'; </script>"; } } ?> <!-- Content --> <div id="content"> <div class="indent"> <p class="p1"> <font size="3"> Aqui poderá expôr as suas dúvidas ou comentários. <br> Coloque o seu E-Mail correcto, para podermos responder o mais breve possível. </font> </p> <form id="contacts-form" action="" method="post"> <div class="field"><label>Nome: </label> <br/> <input type="text" name="nome" value="" size = "30"/> </div> <br/> <div class="field"><label>E-mail: </label> <br/> <input type="text" name="email" onkeypress="checkEmail(event)" value="" size = "30"/> </div> <br/> <div class="field"><label>Menssagem: </label> <br/> <textarea cols="50" rows="15" name="mensagem" value=""></textarea></div> <input type="submit" value="Enviar" name="enviar"> <input type="Reset" value="Apagar Tudo" name="apagar"> </form> </div> </div> Mas só funciona quando estiver no servidor, não funciona no localhost... Depois tens de arranjar uma maneira de listar os emails que tens na BD e seleccionar a quem queres enviar. Se nao me engano ha qualquer coisa em JQuery UI, pesquisa por jquery ui selectable Link to comment Share on other sites More sharing options...
brunoais Posted June 25, 2012 at 02:37 PM Report Share #465375 Posted June 25, 2012 at 02:37 PM o problema é no HTML como tu tens: <input type="text" name="from"> como deve ser: <input type="text" name="from"/> espero ter ajudado Cumps... Vai ler o manual de instruções antes de indicar uma coisa dessas. No HTML 2 <input type="text" name="from"/> É inválido! Ele tinha a tag bem e tu aconselhas a ter a tag mal. "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
MASNathan Posted June 25, 2012 at 03:47 PM Report Share #465393 Posted June 25, 2012 at 03:47 PM Vai ler o manual de instruções antes de indicar uma coisa dessas. No HTML 2 <input type="text" name="from"/> É inválido! Ele tinha a tag bem e tu aconselhas a ter a tag mal. Peço Desculpa Link to comment Share on other sites More sharing options...
brunoais Posted June 25, 2012 at 05:38 PM Report Share #465431 Posted June 25, 2012 at 05:38 PM Peço Desculpa Corrige o post e a desculpa é aceite. "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
ivan919 Posted June 26, 2012 at 09:18 AM Author Report Share #465564 Posted June 26, 2012 at 09:18 AM Bom dia... Queria tirar uma duvida... Ouvi falarem por ai do php.ini, fui procura-lo e la o encontrei, vi na parte do email e encontrei : " ;sendmail_from = postmaster@localhost ". Sempre que enviar um email o From vai ser esse email ("postmaster@localhost")? Consigo receber emails no hotmail ou gmail? ou preciso de configurar alguma coisa? O meu código continua praticamente igual ao que eu mostrei no primeiro post, tentei usar o que me mostravam mas já via muita coisa que nao percebia e nem consegui por a funcionar... Link to comment Share on other sites More sharing options...
ivan919 Posted June 29, 2012 at 03:18 PM Author Report Share #466459 Posted June 29, 2012 at 03:18 PM Boas, Depois de ver na internet, percebi que tinha que configurar o Mercury e segui este site: http://goliatenterrado.es/2009/03/03/configurar-el-mercury32-del-xampp-para-enviar-correos-externos/ Agora quando envio um email pelo script recebo um email com uma mensagem de erro. alguem sabe do que pode ser? aqui vai o codigo que tenho pode ser que ajude: <html> <body> <?php $to= "To: " . $_POST["to"]; $subject = "Subject: " . $_POST["subject"]; $message = " Message: " . $_POST["message"]; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: <********@******.pt>"; if(mail($to, $subject, $message, $headers)) { echo("Mensagem enviada."); } else { echo("Erro no envio do email."); } ?> </body> </html> Link to comment Share on other sites More sharing options...
dash Posted June 29, 2012 at 03:52 PM Report Share #466463 Posted June 29, 2012 at 03:52 PM Para te ser fornecida ajuda, convém sempre indicares a mensagem de erro. Link to comment Share on other sites More sharing options...
ivan919 Posted June 29, 2012 at 03:59 PM Author Report Share #466466 Posted June 29, 2012 at 03:59 PM erro: Delivery to the following recipient failed permanently: To: *********@gmail.com Technical details of permanent failure: Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 550 550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1 http://support.google.com/mail/bin/answer.py?answer=6596 hs4si5612144wib.32 (state 13). Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now