Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Aug 4, 2006, 08:58   #1
Belerofonte
SitePoint Enthusiast
 
Belerofonte's Avatar
 
Join Date: Sep 2004
Location: Brazil
Posts: 91
Mail being send twice or more

Hi all,

I have this php script in simple contact page, but it seems do send the mail twice or even more. Can someone give me a hand plz? The code is down below...

Thanks all!

PHP Code:

<?


  
//Variaveis
  
$nome = $_POST['nome'];
  
$mail = $_POST['mail'];
  
$cidade = $_POST['cidade'];
  
$uf = $_POST['uf'];
  
$telefone = $_POST['telefone'];
  
$ddd = $_POST['ddd'];
  
$comentario = $_POST['comentario'];


  
$toaddress = 'contato@mminf.com.br';
  
$subject = 'Contato | m&m Informática';

  
$mailcontent = 'Nome/Empresa: '.$nome;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'E-Mail: '.$mail;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Cidade: '.$cidade;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Estado: '.$uf;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Telefone: '.$telefone;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'DDD: '.$ddd;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Comentário, dúvida ou sugestão: '.$comentario;

  
$headers  = "MIME-Version: 1.0\r\n";
  
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

  
mail($toaddress, $subject, $mailcontent, $headers);
?>
HTML Code:
<?php
    if(isset($_POST['submit'])) 
	 { ?>
	 
      window.location = "mailsent.html";
	  setDialog(true);

     <?php }
	 else if(isset($_POST['NULL']))
	 { ?>
	 
	  window.location = "erromail.html";		  
	<?php }
?>
</script>


<form method="post" name="contato" action="contato.php" onsubmit="return checkValue();"> 
<table width="500" class="formulario">
  <tr>
    <th width="215" scope="row">Nome / Empresa: </th>
    <td width="269"> <input type="text" name="nome" size="45" maxlength="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"/> </td>
  </tr>
  <tr>
    <th scope="row">Email:</th>
    <td><input type="text" name="mail" size="45" maxlength="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur';"/></td>
  </tr>
  <tr>
    <th scope="row">Cidade / Estado (UF):</th>
    <td><input type="text" name="cidade" size="45" maxlength="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"/>
		<input type="text" name="uf" size="2" maxlength="2" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"/>
	</td>
  </tr>
  <tr>
    <th scope="row">DDD / Telefone: </th>
    <td>
    <input type="text" name="ddd" size="2" maxlength="2" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'" onKeyUp="setNumber(this)" />
    <input type="text" name="telefone" size="8"  maxlength="8" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'" onKeyUp="setNumber(this)" />
	</td>
  </tr>
  <tr>
    <th scope="row" valign="top">D&uacute;vidas, sugest&otilde;es ou cr&iacute;ticas </th>
    <td>
	<textarea name="comentario" rows="5" cols="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"></textarea>
	</td>
  </tr>
  <tr>
    <th colspan="2" scope="row">
	<input type="submit" name="action" value="Enviar" class="actions" />
	<input type="reset" name="action" value="Limpar" class="actions" />
	</th>
    </tr>
</table>
</form>
Belerofonte is offline   Reply With Quote
Old Aug 4, 2006, 09:39   #2
Nova
SitePoint Zealot
 
Nova's Avatar
 
Join Date: Sep 2002
Location: Netherlands
Posts: 127
hmm isn't it a header injection problem? or mail box settings
becouse it should run fine..
Nova is offline   Reply With Quote
Old Aug 4, 2006, 09:59   #3
Belerofonte
SitePoint Enthusiast
 
Belerofonte's Avatar
 
Join Date: Sep 2004
Location: Brazil
Posts: 91
Hey,

It has happened in different pcs, so I guess it isn´t mail configuration.

About the header, I´m not sure, the script is being attached before the html definition, maybe that´s the problem?
Belerofonte is offline   Reply With Quote
Old Aug 4, 2006, 12:15   #4
Belerofonte
SitePoint Enthusiast
 
Belerofonte's Avatar
 
Join Date: Sep 2004
Location: Brazil
Posts: 91
Well,

I´ll post the full php, maybe someone can give me a light about this problem?

Thanks all!

PHP Code:



<?

  
//Variaveis
  
$nome = $_POST['nome'];
  
$mail = $_POST['mail'];
  
$cidade = $_POST['cidade'];
  
$uf = $_POST['uf'];
  
$telefone = $_POST['telefone'];
  
$ddd = $_POST['ddd'];
  
$comentario = $_POST['comentario'];


  
$toaddress = 'contact@contact.com';
  
$subject = 'Contato | m&m Informática';

  
$mailcontent = 'Nome/Empresa: '.$nome;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'E-Mail: '.$mail;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Cidade: '.$cidade;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Estado: '.$uf;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Telefone: '.$telefone;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'DDD: '.$ddd;
  
$mailcontent .= "\r\n";
  
$mailcontent .= 'Comentário, dúvida ou sugestão: '.$comentario;

  
$headers  = "MIME-Version: 1.0\r\n";
  
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

  
mail($toaddress, $subject, $mailcontent, $headers);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>m&m Informática | Tecnologia ao alcance das suas mãos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" src="js/main.js"></script>
<script language="javascript" src="js/validate.js"></script>
<link rel="stylesheet" href="css/cssMain.css" media="screen" />
<link rel="stylesheet" href="css/extras.css" media="screen" />
</style>
</head>

<body>

<!-- Dialogo para mensagens -->
<div class="dialogo" id="dlg"></div>

<!-- Frame principal -->
<div class="main">

  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="950" height="110">
    <param name="movie" value="swf/bannerContato.swf">
    <param name="quality" value="high">
    <param name="wmode" value="transparent">
    <embed src="swf/bannerContato.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="950" height="110"></embed>
  </object>


<h1>O contato constante entre empresa e cliente. Seja bem-vindo a m&amp;m informática</h1>

<div class="quadro">

<script language="javascript">

<?php
    
if(isset($_POST['submit']))
     {
?>

      window.location = "mailsent.html";
      setDialog(true);

     <?php }
     else if(isset(
$_POST['NULL']))
     {
?>

      window.location = "erromail.html";
    <?php }
?>
</script>

<div class="descricaoGeral">
<h2>A m&amp;m Informática quer conhecer você.</h2>
<p>A importância da escolha do servidor adequado para a hospedagem do seu domínio (homepage,
correio eletrônico, aplicativos, etc.) é fundamental para o sucesso da sua empresa na Internet.</p>

<p>Rapidez de acesso, confiabilidade nos serviços de host, o maior tempo possível do site no ar, preços adequados ao mercado sem perda de qualidade são características primordiais do serviço de hospedagem.</p>

<p>Entre em contato e confira o nosso plano de hospedagem com recursos ilimitados em servidor Windows 2003 Server de última geração com os melhores preços do mercado.</p>
</div>

<form method="post" name="contato" action="contato.php" onsubmit="return checkValue();">
<table width="500" class="formulario">
  <tr>
    <th width="215" scope="row">Nome / Empresa: </th>
    <td width="269"> <input type="text" name="nome" size="45" maxlength="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"/> </td>
  </tr>
  <tr>
    <th scope="row">Email:</th>
    <td><input type="text" name="mail" size="45" maxlength="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur';"/></td>
  </tr>
  <tr>
    <th scope="row">Cidade / Estado (UF):</th>
    <td><input type="text" name="cidade" size="45" maxlength="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"/>
        <input type="text" name="uf" size="2" maxlength="2" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"/>
    </td>
  </tr>
  <tr>
    <th scope="row">DDD / Telefone: </th>
    <td>
    <input type="text" name="ddd" size="2" maxlength="2" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'" onKeyUp="setNumber(this)" />
    <input type="text" name="telefone" size="8"  maxlength="8" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'" onKeyUp="setNumber(this)" />
    </td>
  </tr>
  <tr>
    <th scope="row" valign="top">D&uacute;vidas, sugest&otilde;es ou cr&iacute;ticas </th>
    <td>
    <textarea name="comentario" rows="5" cols="45" class="fieldBlur" onFocus="this.className = 'fieldFocus'" onBlur="this.className = 'fieldBlur'"></textarea>
    </td>
  </tr>
  <tr>
    <th colspan="2" scope="row">
    <input type="submit" name="action" value="Enviar" class="actions" />
    <input type="reset" name="action" value="Limpar" class="actions" />
    </th>
    </tr>
</table>
</form>


<div class="clearer"></div>
</div>



<div class="rodape">
<div class="rodapeEsq"></div>
<div class="rodapeDir"></div>
<div class="contRodape">
<h6>2006 | m&minformática - Todos os direitos reservados. O logo m&minformática é propriedade de m&minformática. | Toda e qualquer reprodução é proibida.</h6>
</div>
</div>
</div>


</body>
</html>
Belerofonte is offline   Reply With Quote
Old Aug 4, 2006, 12:23   #5
Dan Grossman
Follow Me On Twitter: @djg
gold trophysilver trophybronze trophy
SitePoint Award Recipient
 
Dan Grossman's Avatar
 
Join Date: Aug 2000
Location: Philadephia, PA
Posts: 19,741
There's nothing conditional about sending the mail -- it sends even when displaying the blank form, before it's filled out.

Check that something was entered before mailing.
Dan Grossman is offline   Reply With Quote
Old Aug 4, 2006, 12:48   #6
Belerofonte
SitePoint Enthusiast
 
Belerofonte's Avatar
 
Join Date: Sep 2004
Location: Brazil
Posts: 91
Hey,

I´m really new about php, can you give me direction about what should I check if null or not?

Thanks!
Belerofonte is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 21:46.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved