473,382 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

HTML email shows as text plain

matheussousuke
249 100+
I'm having trouble with e-mail sending, I mean, the website is suposed to send a confirmation email after sign up, but it gets like text plain instead of HTML

May someone help me, please?

Here's the code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. require_once 'path_cnfg.php';
  5.  
  6. require_once(path_cnfg('pathToLibDir').'func_common.php');
  7. require_once(path_cnfg('pathToLibDir').'func_checkUser.php');
  8. require_once(path_cnfg('pathToCnfgDir').'cnfg_vars.php');
  9. require_once(path_cnfg('pathToLibDir').'vars_gbl.php');
  10.  
  11. $myDB = db_connect();
  12.  
  13. $cookie = $HTTP_COOKIE_VARS['log_in_cookie'];
  14.  
  15. $content = array();
  16.  
  17. $submit = $HTTP_POST_VARS["submit"];
  18.  
  19. if ( !checkUser('', '') )
  20. {   if ( $submit && $submit != 'validate' && checkForm() )
  21.     {   $gbl["try_register"] = true;
  22.         if ( prelim_insert() )
  23.         {   $gbl["register_message"] = 'Um código de registro foi enviado para seu endereço de email.<BR>Siga as instruções no email para verificar seu registro.<BR>' ; 
  24.         }
  25.         else
  26.         {   $gbl["register_message"] = 'O registro preliminar falhou.<BR>'.$gbl["register_message"];
  27.         } 
  28.     }
  29.  
  30. }
  31.  
  32.  
  33. if ($gbl["loggedIn"])
  34. {   $content[] = "echo 'Você já está logado no sistema.';";
  35. }
  36. elseif (!$submit)
  37. {   $content[] = "echo 'Apenas números, letras, e o caractere underline( _ ) são permitidos no nome de usuário.<BR>';";
  38.     $content[] = 'doForm();';
  39. }
  40. elseif ($gbl["errors"]!="")
  41. {   $content[] = "echo '<font class=\"errorBig\">Erros:<BR></font>';";
  42.     $content[] = "echo '<font class=\"errorLittle\">';" ;
  43.     $content[] = 'echo $gbl["errors"] ;' ;
  44.     $content[] = 'echo "</font><BR>";' ;
  45.     #echo $content[(count($content)-1)]."<BR>";
  46.     $content[] = 'doForm();';
  47. elseif ($gbl["try_register"])
  48. {   $content[] = 'echo $gbl["register_message"];';
  49. }
  50.  
  51. // This line brings in the template file.
  52. // If you want to use a different template file 
  53. // simply change this line to require the template 
  54. // file that you want to use.
  55. require_once(path_cnfg('pathToTemplatesDir').cnfg('tmplt_register'));
  56.  
  57. db_disconnect($myDB);
  58.  
  59.  
  60. # --- START FUNCTIONS ---
  61.  
  62.  
  63. // *********** START FUNCTION prelim_insert() *************
  64.  
  65. function prelim_insert()
  66.     GLOBAL $gbl, $myDB, $HTTP_POST_VARS ;
  67.  
  68.     $new_user_name = $HTTP_POST_VARS["new_user_name"];
  69.     $email = $HTTP_POST_VARS["email"];
  70.     $password1 = $HTTP_POST_VARS["password1"];
  71.  
  72.  
  73.     $query = "SELECT user_name FROM std_users 
  74.               WHERE user_name='$new_user_name'";
  75.  
  76.     $result = mysql_query($query, $myDB);
  77.  
  78.     if (mysql_num_rows($result) > 0)
  79.     {   $gbl["register_message"] .= 'Sinto muito, mas este nome de usuário já está sendo usado, por favor digite outro nome.<BR>';
  80.         return false;
  81.     }
  82.  
  83.     srand((double)microtime()*1000000);
  84.  
  85.     $the_rand = rand(1, 10000);
  86.     $the_rand2 = rand(1, 10000);
  87.     $the_rand3 = rand(1, 10000);
  88.  
  89.     $the_rand = ''.$the_rand.''.$the_rand2.''.$the_rand3;
  90.  
  91.     $query = "INSERT INTO std_temp_users(user_name, password, email, sign_up_date, prelim_rand) VALUES('$new_user_name', '$password1', '$email', ".time().", '$the_rand')";
  92.  
  93.     $result = mysql_query($query, $myDB);
  94.  
  95.     if (!$result) 
  96.     {   if ( preg_match("/duplicate entry/i", mysql_error()) )
  97.         {   $gbl["errors"] .= "Por favor digite outro nome de usuário.<BR>
  98.                                 Este já está em uso.";
  99.         }
  100.  
  101.         return false;
  102.     }
  103.  
  104.     $to = $email;
  105.     $subject = 'Seu cadastro';
  106.  
  107.     $the_link = cnfg('deDir').'verify_registration.php';
  108.  
  109.     $message = '<html><body>
  110.  
  111.  
  112.  
  113.     Por favor siga estas instruções para verificar seu registro:
  114.     <BR>
  115.     1. Clique no link abaixo:
  116.     <BR>
  117.     2. Digite o usuário e o código de confirmação que está localizado abaixo desta linha.
  118.     <BR>
  119.     <BR>
  120.     Observação: Após verificar seu cadastro você fará login no site usando o nome usuário e senha  que você cadastrou. 
  121.     <BR>
  122.     O código de confirmação é usado apenas para confirmar o seu cadastro.
  123.     <BR>
  124.     <BR>
  125.     Username: '.$new_user_name.'
  126.     <BR>
  127.     Código de confirmação:  '.$the_rand.'
  128.     <BR>
  129.     <BR>
  130.      ' ;
  131.  
  132.     $message .= "<a href=\"$the_link\">$the_link</a>";
  133.  
  134.     $message .= '</body></html>';
  135.  
  136.  
  137.     #$headers = "MIME-Version: 1.0\r\n";
  138.     #$headers .= "Return-Path: <".cnfg('replyEmail').">\r\n";
  139.     #$headers .= "X-Sender: <".cnfg('replyEmail').">\r\n"; 
  140.     #$headers .= "X-Mailer: PHP\r\n"; // mailer
  141.     $headers .= "De: <".cnfg('replyEmail').">".$gbl['newLine'];
  142.     $headers .= "Responder para: <".cnfg('replyEmail').">".$gbl['newLine'];
  143.     $headers .= "tipo de conteúdo: text/html; charset=iso-8859-1".$gbl['newLine'];
  144.  
  145.  
  146.     if ($result) 
  147.     {   if ( mail($to, $subject, $message, $headers) )
  148.         {   return true;
  149.         }
  150.         else
  151.         {   echo 'erro ao enviar email<BR>';
  152.             return false;
  153.         }
  154.     }
  155.     else 
  156.     {   return false;
  157.     }
  158.  
  159. } // end function prelim_insert()
  160.  
  161. // *********** END FUNCTION prelim_insert() *************
  162.  
  163.  
  164. // *********** START FUNCTION doForm() *************
  165.  
  166. function doForm()
  167. {
  168.     GLOBAL $HTTP_POST_VARS ;
  169.  
  170.     $new_user_name = $HTTP_POST_VARS["new_user_name"];
  171.     $password1 = $HTTP_POST_VARS["password1"];
  172.     $password2 = $HTTP_POST_VARS["password2"];
  173.     $email = $HTTP_POST_VARS["email"];
  174.  
  175.     if (!$submit || $errors!="")
  176.     {
  177.         ?>
  178.  
  179.  
  180.         <FORM ACTION="<?php echo cnfg('deDir'); ?>register.php" METHOD="POST">
  181.         <table width="741" border="0" cellpadding="0" cellspacing="0">
  182.           <!--DWLayoutTable-->
  183.         <BR>
  184.         <tr><td height="22" colspan="4" align="right" valign="top"> Nome de usuário: </td>
  185.         <td colspan="3" align="left" valign="baseline">
  186.           <INPUT TYPE="TEXT" NAME="new_user_name" value="<?php echo $new_user_name; ?>" SIZE="15">        </td>
  187.         <td colspan="2" rowspan="2" valign="top"><div align="center"><strong>Embora este site seja seguro, não é possível evitar tentativas de invasão de hackers, por favor, evite usar senhas pessoais, como por exemplo, senhas de email.</strong></div></td>
  188.         <td width="1"></td>
  189.         </tr>
  190.         <tr><td colspan="4" rowspan="2" align="right" valign="top">
  191.         Senha:
  192.         </td>
  193.         <td colspan="3" rowspan="2" align="left" valign="baseline">
  194.           <INPUT TYPE="PASSWORD" NAME="password1" value="<?php echo $password1; ?>" SIZE="15">        </td>
  195.         <td height="16"></td>
  196.         </tr>
  197.         <tr>
  198.           <td width="57" height="6"></td>
  199.           <td width="317"></td>
  200.           <td></td>
  201.         </tr>
  202.         <tr><td height="22" colspan="4" align="right" valign="top">
  203.         Digite sua senha novamente:
  204.         </td>
  205.         <td colspan="3" align="left" valign="baseline">
  206.           <INPUT TYPE="PASSWORD" NAME="password2" value="<?php echo $password2; ?>" SIZE="15">        </td>
  207.         <td></td>
  208.         <td></td>
  209.         <td></td>
  210.         </tr>
  211.  
  212.  
  213.  
  214.         <tr><td height="19" colspan="4" align="right" valign="top"> Endereço de Email: </td>
  215.         <td colspan="3" rowspan="2" align="left" valign="baseline">
  216.           <INPUT TYPE="TEXT" NAME="email" value="<?php echo $email; ?>" SIZE="15">        </td>
  217.         <td></td>
  218.         <td></td>
  219.         <td></td>
  220.         </tr>
  221.         <tr>
  222.           <td width="76" height="3"></td>
  223.           <td width="119"></td>
  224.           <td width="49"></td>
  225.           <td width="32"></td>
  226.           <td></td>
  227.           <td></td>
  228.           <td></td>
  229.         </tr>
  230.         <tr>
  231.           <td height="24"></td>
  232.           <td></td>
  233.           <td></td>
  234.           <td colspan="2" valign="top"><input type="SUBMIT" name="submit" value="Enviar" /></td>
  235.           <td width="39">&nbsp;</td>
  236.           <td width="32">&nbsp;</td>
  237.           <td></td>
  238.           <td></td>
  239.           <td></td>
  240.         </tr>
  241.         <tr>
  242.           <td height="14"></td>
  243.           <td></td>
  244.           <td></td>
  245.           <td></td>
  246.           <td width="19"></td>
  247.           <td></td>
  248.           <td></td>
  249.           <td></td>
  250.           <td></td>
  251.           <td></td>
  252.         </tr>
  253.         <tr>
  254.           <td height="19"></td>
  255.           <td></td>
  256.           <td colspan="4" valign="top"><p><strong>Termos de utiliza&ccedil;&atilde;o</strong></p></td>
  257.           <td>&nbsp;</td>
  258.           <td></td>
  259.           <td></td>
  260.           <td></td>
  261.         </tr>
  262.         <tr>
  263.           <td height="17"></td>
  264.           <td></td>
  265.           <td></td>
  266.           <td></td>
  267.           <td></td>
  268.           <td></td>
  269.           <td></td>
  270.           <td></td>
  271.           <td></td>
  272.           <td></td>
  273.         </tr>
  274.         <tr>
  275.           <td height="163"></td>
  276.           <td colspan="7" valign="top"><textarea name="textarea" cols="55" rows="10">Apesar dos administradores deste site tentarem remover ou editar qualquer material indesejável logo que detectado, é impossível rever todos os anúncios. Como tal você reconhece por este meio que todos os anúncios colocados no site expressam os pontos de vista e opiniões dos seus respectivos autores e não dos administradores, moderadores ou o encarregado das páginas (exceto anúncios colocados por essas pessoas) não sendo por tais responsáveis.
  277.  
  278. Você aceita não colocar qualquer mensagem ou imagem abusiva, obscena, invulgar, insultuosa, de ódio, ameaçadora, sexualmente tendenciosa ou qualquer outro material que possa violar qualquer lei em vigor, como por exemplo, pedofilia e racismo. Se tal acontecer isso irá conduzir à sua expulsão imediata e permanente (além de ser notificado o seu fornecedor de Internet). Você concorda que quem faz e mantém estas páginas, administradores deste site têm o direito de remover, editar, mover ou encerrar qualquer anúncio em qualquer altura que eles assim o entendam e seja implícito. Como utilizador você aceita que qualquer informação que forneceu acima seja guardada numa base de dados. Apesar dessa informação não ser fornecida a terceiros sem a sua autorização, o encarregado das páginas, administradores não podem assumir a responsabilidade por qualquer tentativa de ato de "hacking" (intromissão forçada e ilegal que conduza a essa informação ser exposta). 
  279.  
  280. Este sistema de anúncios usa "cookies" para guardar informação no seu computador. Esses "cookies" não possuem nenhuma das informações acima fornecidas, apenas serve para melhorar o seu prazer a quando e enquanto visita este site. O endereço de e-mail é apenas usado para confirmar a informação do seu registro e a senha (bem como para enviar novas senhas caso se esqueça da que acabou de submeter). 
  281.  
  282. Ao clicar em “Enviar”, você concorda com as condições impostas nos Termos de Utilização.</textarea></td>
  283.           <td>&nbsp;</td>
  284.           <td></td>
  285.         </tr>
  286.         <tr>
  287.           <td height="35"></td>
  288.           <td>&nbsp;</td>
  289.           <td></td>
  290.           <td></td>
  291.           <td></td>
  292.           <td></td>
  293.           <td></td>
  294.           <td></td>
  295.           <td></td>
  296.           <td></td>
  297.         </tr>
  298.         </table>
  299.  
  300.         </FORM>
  301.  
  302.         <?php 
  303.  
  304.     } // end if
  305.  
  306. } // end function doForm()
  307.  
  308. // *********** END FUNCTION doForm() *************
  309.  
  310. // *********** START FUNCTION checkForm() *************
  311. function checkForm()
  312. {
  313.     GLOBAL $gbl, $HTTP_POST_VARS ;
  314.  
  315.  
  316.     $new_user_name = $HTTP_POST_VARS['new_user_name'];
  317.     $password1 = $HTTP_POST_VARS['password1'];
  318.     $password2 = $HTTP_POST_VARS['password2'];
  319.     $email = $HTTP_POST_VARS['email'];
  320.     $submit = $HTTP_POST_VARS['submit'];
  321.  
  322.     if ($submit)
  323.     {   if ($new_user_name)
  324.         {   if ( preg_match("/[^0-9a-zA-Z_]/", $new_user_name ) )
  325.             {   $gbl['errors'] .= '• Invalid characters<BR>' ;
  326.                 $new_user_name='';
  327.             }
  328.  
  329.             if ( (strlen($new_user_name) < cnfg('userNameMinLength') )
  330.                  || (strlen($new_user_name) > cnfg('userNameMaxLength') ) )
  331.             {   $gbl['errors'] .= '• Nomes de usuários devem ter menos de ';
  332.                 $gbl['errors'] .= cnfg('userNameMaxLength').', e mais de ';
  333.                 $gbl['errors'] .= cnfg('userNameMinLength').' caracteres.<BR>'; 
  334.             }
  335.  
  336.  
  337.         }
  338.         else
  339.         {   $gbl['errors'] .= '• Você não digitou um nome de usuário.<BR>';
  340.         }
  341.  
  342.  
  343.         if($password1 && $password2)
  344.         {   if($password1 != $password2)
  345.             {   $gbl['errors'] .= '• As senhas digitadas não correspondem uma a outra<BR>';
  346.                 $password1 = ''; 
  347.                 $password2 = '';
  348.             }
  349.  
  350.             if ( (strlen($password1) < cnfg('userPassMinLength') )
  351.                  || (strlen($password1) > cnfg('userPassMaxLength') ) )
  352.             {   $gbl['errors'] .= '• Senhas devem ter menos de ';
  353.                 $gbl['errors'] .= cnfg('userPassMaxLength').', e mais de ';
  354.                 $gbl['errors'] .= cnfg('userPassMinLength').' caracteres.<BR>';
  355.             }
  356.         }
  357.         else
  358.         {   $gbl['errors'] .= '• Você precisa digitar uma senha.<BR>';
  359.             $password1 = ''; 
  360.             $password2 = '';
  361.         }
  362.  
  363.  
  364.         if ($email)
  365.         {   if ( !preg_match("/([\w\-\.])+@([\w\-\.])+\.([a-zA-Z])+/i", $email) )
  366.             {   $gbl['errors'] .= '• Endereço de e-mail inexistente.<BR>';
  367.                 $email = '';
  368.             }
  369.         }
  370.         else
  371.         {   $gbl['errors'] .= '• Você precisa digitar um endereço de email.<BR>';
  372.         }
  373.     } // end if($submit) 
  374.  
  375.  
  376.     if ($gbl['errors'] != '')
  377.     {   return false; 
  378.     }
  379.     else
  380.     {   return true; 
  381.     }
  382.  
  383. } // end function checkForm()
  384.  
  385. // *********** END FUNCTION checkForm() *************
  386.  
  387. ?>
  388.  
Nov 19 '09 #1
27 4761
matheussousuke
249 100+
This how it appears on the email:




Expand|Select|Wrap|Line Numbers
  1. Responder para: <email@example.com>
  2. tipo de conteúdo: text/html; charset=iso-8859-1
  3.  
  4.  
  5. <html><body>
  6.  
  7.  
  8.  
  9.     Por favor siga estas instruções para verificar seu registro:
  10.     <BR>
  11.     1. Clique no link abaixo:
  12.     <BR>
  13.     2. Digite o usuário e o código de confirmação que está localizado abaixo desta
  14. linha.
  15.     <BR>
  16.     <BR>
  17.     Observação: Após verificar seu cadastro você fará login no site usando o nome
  18. usuário e senha  que você cadastrou. 
  19.     <BR>
  20.     O código de confirmação é usado apenas para confirmar o seu cadastro.
  21.     <BR>
  22.     <BR>
  23.     Username: jackbouer3
  24.     <BR>
  25.     Código de confirmação:  662849454704
  26.     <BR>
  27.     <BR>
  28.      <a
  29. href="/anuncieaki/verify_registration.php">/anuncieaki/verify_registration.php</a></body></html>
Nov 19 '09 #2
matheussousuke
249 100+
@matheussousuke


I know the code is a quite long, so I posted the part where I think the error is:
This:


Expand|Select|Wrap|Line Numbers
  1. // *********** START FUNCTION prelim_insert() *************
  2.  
  3. function prelim_insert()
  4.     GLOBAL $gbl, $myDB, $HTTP_POST_VARS ;
  5.  
  6.     $new_user_name = $HTTP_POST_VARS["new_user_name"];
  7.     $email = $HTTP_POST_VARS["email"];
  8.     $password1 = $HTTP_POST_VARS["password1"];
  9.  
  10.  
  11.     $query = "SELECT user_name FROM std_users 
  12.               WHERE user_name='$new_user_name'";
  13.  
  14.     $result = mysql_query($query, $myDB);
  15.  
  16.     if (mysql_num_rows($result) > 0)
  17.     {   $gbl["register_message"] .= 'Sinto muito, mas este nome de usuário já está sendo usado, por favor digite outro nome.<BR>';
  18.         return false;
  19.     }
  20.  
  21.     srand((double)microtime()*1000000);
  22.  
  23.     $the_rand = rand(1, 10000);
  24.     $the_rand2 = rand(1, 10000);
  25.     $the_rand3 = rand(1, 10000);
  26.  
  27.     $the_rand = ''.$the_rand.''.$the_rand2.''.$the_rand3;
  28.  
  29.     $query = "INSERT INTO std_temp_users(user_name, password, email, sign_up_date, prelim_rand) VALUES('$new_user_name', '$password1', '$email', ".time().", '$the_rand')";
  30.  
  31.     $result = mysql_query($query, $myDB);
  32.  
  33.     if (!$result) 
  34.     {   if ( preg_match("/duplicate entry/i", mysql_error()) )
  35.         {   $gbl["errors"] .= "Por favor digite outro nome de usuário.<BR>
  36.                                 Este já está em uso.";
  37.         }
  38.  
  39.         return false;
  40.     }
  41.  
  42.     $to = $email;
  43.     $subject = 'Seu cadastro';
  44.  
  45.     $the_link = cnfg('deDir').'verify_registration.php';
  46.  
  47.     $message = '<html><body>
  48.  
  49.  
  50.  
  51.     Por favor siga estas instruções para verificar seu registro:
  52.     <BR>
  53.     1. Clique no link abaixo:
  54.     <BR>
  55.     2. Digite o usuário e o código de confirmação que está localizado abaixo desta linha.
  56.     <BR>
  57.     <BR>
  58.     Observação: Após verificar seu cadastro você fará login no site usando o nome usuário e senha  que você cadastrou. 
  59.     <BR>
  60.     O código de confirmação é usado apenas para confirmar o seu cadastro.
  61.     <BR>
  62.     <BR>
  63.     Username: '.$new_user_name.'
  64.     <BR>
  65.     Código de confirmação:  '.$the_rand.'
  66.     <BR>
  67.     <BR>
  68.      ' ;
  69.  
  70.     $message .= "<a href=\"$the_link\">$the_link</a>";
  71.  
  72.     $message .= '</body></html>';
  73.  
  74.  
  75.     #$headers = "MIME-Version: 1.0\r\n";
  76.     #$headers .= "Return-Path: <".cnfg('replyEmail').">\r\n";
  77.     #$headers .= "X-Sender: <".cnfg('replyEmail').">\r\n"; 
  78.     #$headers .= "X-Mailer: PHP\r\n"; // mailer
  79.     $headers .= "De: <".cnfg('replyEmail').">".$gbl['newLine'];
  80.     $headers .= "Responder para: <".cnfg('replyEmail').">".$gbl['newLine'];
  81.     $headers .= "tipo de conteúdo: text/html; charset=iso-8859-1".$gbl['newLine'];
  82.  
  83.  
  84.     if ($result) 
  85.     {   if ( mail($to, $subject, $message, $headers) )
  86.         {   return true;
  87.         }
  88.         else
  89.         {   echo 'erro ao enviar email<BR>';
  90.             return false;
  91.         }
  92.     }
  93.     else 
  94.     {   return false;
  95.     }
  96.  
  97. } // end function prelim_insert()
  98.  
  99. // *********** END FUNCTION prelim_insert() *************
  100.  
  101.  
Nov 19 '09 #3
matheussousuke
249 100+
Somebody there?
Somebody there?
Nov 19 '09 #4
Dormilich
8,658 Expert Mod 8TB
@matheussousuke
no, we are having our beauty sleep.

anyways, when it comes to HTML mail, I usually use mail libraries like SwiftMailer which are easier to use than trying to get mail() sending the HTML.
Nov 20 '09 #5
Atli
5,058 Expert 4TB
Hey.

Expand|Select|Wrap|Line Numbers
  1.  $headers .= "tipo de conteúdo: text/html; charset=iso-8859-1".$gbl['newLine'];
I'm pretty sure this is supposed to be in English.
Have you tried that?

I understand the need to localize things, but it is usually not a good idea to try to localize the actual code. It's best to leave that in English :-)

P.S.
The $HTTP_POST_VARS array was deprecated with PHP 4.1.
If you are coding in PHP 4.1 or higher, you should be using $_POST instead.
Nov 20 '09 #6
matheussousuke
249 100+
@Atli

Well, yeah, I know, it's in portuguese, but there's nothing important to be translated to english, what is in portuguese are things like "Here is your confirmation code", u know, nothing to do to the code, but thanks, I'll follow the advice.

Let me see if that works using "$_POST".
thanks again.
Nov 20 '09 #7
matheussousuke
249 100+
@matheussousuke

Post didn't work. =/
Nov 20 '09 #8
matheussousuke
249 100+
@Dormilich

Downloaded it, how do I use it?
Nov 20 '09 #9
Markus
6,050 Expert 4TB
@matheussousuke
Headers should be sent in English. That is, the header should be: Content-type: text/html;
Nov 20 '09 #10
Dormilich
8,658 Expert Mod 8TB
@matheussousuke
check out SwiftMailer’s documentation, everything is explained there.
Nov 20 '09 #11
matheussousuke
249 100+
@Atli

Oh, sorry, didn see u posted a code. Yeah, that should be in english.
Nov 20 '09 #12
matheussousuke
249 100+
@Atli



There are $HTTP_COOKIE_VARS, do I have to change it to $POST_VARS ???
Nov 20 '09 #13
Dormilich
8,658 Expert Mod 8TB
change $HTTP_COOKIE_VARS to $_COOKIE
Nov 20 '09 #14
matheussousuke
249 100+
headers are in english now, but nothing works.
Nov 20 '09 #15
matheussousuke
249 100+
also changed $HTTP_POST_VARS and the cookie one. still doesnt works.
Nov 20 '09 #16
matheussousuke
249 100+
What does $HTTP_POST_VARS do?
Nov 20 '09 #17
matheussousuke
249 100+
@Dormilich
Now the code's like this:


Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3.  
  4. require_once 'path_cnfg.php';
  5.  
  6. require_once(path_cnfg('pathToLibDir').'func_common.php');
  7. require_once(path_cnfg('pathToLibDir').'func_checkUser.php');
  8. require_once(path_cnfg('pathToCnfgDir').'cnfg_vars.php');
  9. require_once(path_cnfg('pathToLibDir').'vars_gbl.php');
  10.  
  11. $myDB = db_connect();
  12.  
  13. $cookie = $_COOKIE['log_in_cookie'];
  14.  
  15. $content = array();
  16.  
  17. $submit = $_POST["submit"];
  18.  
  19. if ( !checkUser('', '') )
  20. {   if ( $submit && $submit != 'validate' && checkForm() )
  21.     {   $gbl["try_register"] = true;
  22.         if ( prelim_insert() )
  23.         {   $gbl["register_message"] = 'Um código de registro foi enviado para seu endereço de email.<BR>Siga as instruções no email para verificar seu registro.<BR>' ; 
  24.         }
  25.         else
  26.         {   $gbl["register_message"] = 'O registro preliminar falhou.<BR>'.$gbl["register_message"];
  27.         } 
  28.     }
  29.  
  30. }
  31.  
  32.  
  33. if ($gbl["loggedIn"])
  34. {   $content[] = "echo 'Você já está logado no sistema.';";
  35. }
  36. elseif (!$submit)
  37. {   $content[] = "echo 'Apenas números, letras, e o caractere underline( _ ) são permitidos no nome de usuário.<BR>';";
  38.     $content[] = 'doForm();';
  39. }
  40. elseif ($gbl["errors"]!="")
  41. {   $content[] = "echo '<font class=\"errorBig\">Erros:<BR></font>';";
  42.     $content[] = "echo '<font class=\"errorLittle\">';" ;
  43.     $content[] = 'echo $gbl["errors"] ;' ;
  44.     $content[] = 'echo "</font><BR>";' ;
  45.     #echo $content[(count($content)-1)]."<BR>";
  46.     $content[] = 'doForm();';
  47. elseif ($gbl["try_register"])
  48. {   $content[] = 'echo $gbl["register_message"];';
  49. }
  50.  
  51. // This line brings in the template file.
  52. // If you want to use a different template file 
  53. // simply change this line to require the template 
  54. // file that you want to use.
  55. require_once(path_cnfg('pathToTemplatesDir').cnfg('tmplt_register'));
  56.  
  57. db_disconnect($myDB);
  58.  
  59.  
  60. # --- START FUNCTIONS ---
  61.  
  62.  
  63. // *********** START FUNCTION prelim_insert() *************
  64.  
  65. function prelim_insert()
  66.     GLOBAL $gbl, $myDB, $_POST ;
  67.  
  68.     $new_user_name = $_POST["new_user_name"];
  69.     $email = $_POST["email"];
  70.     $password1 = $_POST["password1"];
  71.  
  72.  
  73.     $query = "SELECT user_name FROM std_users 
  74.               WHERE user_name='$new_user_name'";
  75.  
  76.     $result = mysql_query($query, $myDB);
  77.  
  78.     if (mysql_num_rows($result) > 0)
  79.     {   $gbl["register_message"] .= 'Sinto muito, mas este nome de usuário já está sendo usado, por favor digite outro nome.<BR>';
  80.         return false;
  81.     }
  82.  
  83.     srand((double)microtime()*1000000);
  84.  
  85.     $the_rand = rand(1, 10000);
  86.     $the_rand2 = rand(1, 10000);
  87.     $the_rand3 = rand(1, 10000);
  88.  
  89.     $the_rand = ''.$the_rand.''.$the_rand2.''.$the_rand3;
  90.  
  91.     $query = "INSERT INTO std_temp_users(user_name, password, email, sign_up_date, prelim_rand) VALUES('$new_user_name', '$password1', '$email', ".time().", '$the_rand')";
  92.  
  93.     $result = mysql_query($query, $myDB);
  94.  
  95.     if (!$result) 
  96.     {   if ( preg_match("/duplicate entry/i", mysql_error()) )
  97.         {   $gbl["errors"] .= "Por favor digite outro nome de usuário.<BR>
  98.                                 Este já está em uso.";
  99.         }
  100.  
  101.         return false;
  102.     }
  103.  
  104.     $to = $email;
  105.     $subject = 'Seu cadastro';
  106.  
  107.     $the_link = cnfg('deDir').'verify_registration.php';
  108.  
  109.     $message = '<html><body>
  110.  
  111.  
  112.  
  113.     Por favor siga estas instruções para verificar seu registro:
  114.     <BR>
  115.     1. Clique no link abaixo:
  116.     <BR>
  117.     2. Digite o usuário e o código de confirmação que está localizado abaixo desta linha.
  118.     <BR>
  119.     <BR>
  120.     Observação: Após verificar seu cadastro você fará login no site usando o nome usuário e senha  que você cadastrou. 
  121.     <BR>
  122.     O código de confirmação é usado apenas para confirmar o seu cadastro.
  123.     <BR>
  124.     <BR>
  125.     Username: '.$new_user_name.'
  126.     <BR>
  127.     Código de confirmação:  '.$the_rand.'
  128.     <BR>
  129.     <BR>
  130.      ' ;
  131.  
  132.     $message .= "<a href=\"$the_link\">$the_link</a>";
  133.  
  134.     $message .= '</body></html>';
  135.  
  136.  
  137.     #$headers = "MIME-Version: 1.0\r\n";
  138.     #$headers .= "Return-Path: <".cnfg('replyEmail').">\r\n";
  139.     #$headers .= "X-Sender: <".cnfg('replyEmail').">\r\n"; 
  140.     #$headers .= "X-Mailer: PHP\r\n"; // mailer
  141.  
  142.  
  143.     $headers .= "From: <".cnfg('replyEmail').">".$gbl['newLine'];
  144.     $headers .= "Reply-To: <".cnfg('replyEmail').">".$gbl['newLine'];
  145.     $headers .= "Content-type: text/html; charset=iso-8859-1".$gbl['newLine'];
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.     if ($result) 
  154.     {   if ( mail($to, $subject, $message, $headers) )
  155.         {   return true;
  156.         }
  157.         else
  158.         {   echo 'erro ao enviar email<BR>';
  159.             return false;
  160.         }
  161.     }
  162.     else 
  163.     {   return false;
  164.     }
  165.  
  166. } // end function prelim_insert()
  167.  
  168. // *********** END FUNCTION prelim_insert() *************
  169.  
  170.  
  171. // *********** START FUNCTION doForm() *************
  172.  
  173. function doForm()
  174. {
  175.     GLOBAL $_POST ;
  176.  
  177.     $new_user_name = $_POST["new_user_name"];
  178.     $password1 = $_POST["password1"];
  179.     $password2 = $_POST["password2"];
  180.     $email = $_POST["email"];
  181.  
  182.     if (!$submit || $errors!="")
  183.     {
  184.         ?>
  185.  
  186.  
  187.         <FORM ACTION="<? echo cnfg('deDir'); ?>register.php" METHOD="POST">
  188.         <table width="741" border="0" cellpadding="0" cellspacing="0">
  189.           <!--DWLayoutTable-->
  190.         <BR>
  191.         <tr><td height="22" colspan="4" align="right" valign="top"> Nome de usuário: </td>
  192.         <td colspan="3" align="left" valign="baseline">
  193.           <INPUT TYPE="TEXT" NAME="new_user_name" value="<? echo $new_user_name; ?>" SIZE="15">        </td>
  194.         <td colspan="2" rowspan="2" valign="top"><div align="center"><strong>Embora este site seja seguro, não é possível evitar tentativas de invasão de hackers, por favor, evite usar senhas pessoais, como por exemplo, senhas de email.</strong></div></td>
  195.         <td width="1"></td>
  196.         </tr>
  197.         <tr><td colspan="4" rowspan="2" align="right" valign="top">
  198.         Senha:
  199.         </td>
  200.         <td colspan="3" rowspan="2" align="left" valign="baseline">
  201.           <INPUT TYPE="PASSWORD" NAME="password1" value="<? echo $password1; ?>" SIZE="15">        </td>
  202.         <td height="16"></td>
  203.         </tr>
  204.         <tr>
  205.           <td width="57" height="6"></td>
  206.           <td width="317"></td>
  207.           <td></td>
  208.         </tr>
  209.         <tr><td height="22" colspan="4" align="right" valign="top">
  210.         Digite sua senha novamente:
  211.         </td>
  212.         <td colspan="3" align="left" valign="baseline">
  213.           <INPUT TYPE="PASSWORD" NAME="password2" value="<? echo $password2; ?>" SIZE="15">        </td>
  214.         <td></td>
  215.         <td></td>
  216.         <td></td>
  217.         </tr>
  218.  
  219.  
  220.  
  221.         <tr><td height="19" colspan="4" align="right" valign="top"> Endereço de Email: </td>
  222.         <td colspan="3" rowspan="2" align="left" valign="baseline">
  223.           <INPUT TYPE="TEXT" NAME="email" value="<? echo $email; ?>" SIZE="15">        </td>
  224.         <td></td>
  225.         <td></td>
  226.         <td></td>
  227.         </tr>
  228.         <tr>
  229.           <td width="76" height="3"></td>
  230.           <td width="119"></td>
  231.           <td width="49"></td>
  232.           <td width="32"></td>
  233.           <td></td>
  234.           <td></td>
  235.           <td></td>
  236.         </tr>
  237.         <tr>
  238.           <td height="24"></td>
  239.           <td></td>
  240.           <td></td>
  241.           <td colspan="2" valign="top"><input type="SUBMIT" name="submit" value="Enviar" /></td>
  242.           <td width="39">&nbsp;</td>
  243.           <td width="32">&nbsp;</td>
  244.           <td></td>
  245.           <td></td>
  246.           <td></td>
  247.         </tr>
  248.         <tr>
  249.           <td height="14"></td>
  250.           <td></td>
  251.           <td></td>
  252.           <td></td>
  253.           <td width="19"></td>
  254.           <td></td>
  255.           <td></td>
  256.           <td></td>
  257.           <td></td>
  258.           <td></td>
  259.         </tr>
  260.         <tr>
  261.           <td height="19"></td>
  262.           <td></td>
  263.           <td colspan="4" valign="top"><p><strong>Termos de utiliza&ccedil;&atilde;o</strong></p></td>
  264.           <td>&nbsp;</td>
  265.           <td></td>
  266.           <td></td>
  267.           <td></td>
  268.         </tr>
  269.         <tr>
  270.           <td height="17"></td>
  271.           <td></td>
  272.           <td></td>
  273.           <td></td>
  274.           <td></td>
  275.           <td></td>
  276.           <td></td>
  277.           <td></td>
  278.           <td></td>
  279.           <td></td>
  280.         </tr>
  281.         <tr>
  282.           <td height="163"></td>
  283.           <td colspan="7" valign="top"><textarea name="textarea" cols="55" rows="10">Apesar dos administradores deste site tentarem remover ou editar qualquer material indesejável logo que detectado, é impossível rever todos os anúncios. Como tal você reconhece por este meio que todos os anúncios colocados no site expressam os pontos de vista e opiniões dos seus respectivos autores e não dos administradores, moderadores ou o encarregado das páginas (exceto anúncios colocados por essas pessoas) não sendo por tais responsáveis.
  284.  
  285. Você aceita não colocar qualquer mensagem ou imagem abusiva, obscena, invulgar, insultuosa, de ódio, ameaçadora, sexualmente tendenciosa ou qualquer outro material que possa violar qualquer lei em vigor, como por exemplo, pedofilia e racismo. Se tal acontecer isso irá conduzir à sua expulsão imediata e permanente (além de ser notificado o seu fornecedor de Internet). Você concorda que quem faz e mantém estas páginas, administradores deste site têm o direito de remover, editar, mover ou encerrar qualquer anúncio em qualquer altura que eles assim o entendam e seja implícito. Como utilizador você aceita que qualquer informação que forneceu acima seja guardada numa base de dados. Apesar dessa informação não ser fornecida a terceiros sem a sua autorização, o encarregado das páginas, administradores não podem assumir a responsabilidade por qualquer tentativa de ato de "hacking" (intromissão forçada e ilegal que conduza a essa informação ser exposta). 
  286.  
  287. Este sistema de anúncios usa "cookies" para guardar informação no seu computador. Esses "cookies" não possuem nenhuma das informações acima fornecidas, apenas serve para melhorar o seu prazer a quando e enquanto visita este site. O endereço de e-mail é apenas usado para confirmar a informação do seu registro e a senha (bem como para enviar novas senhas caso se esqueça da que acabou de submeter). 
  288.  
  289. Ao clicar em “Enviar”, você concorda com as condições impostas nos Termos de Utilização.</textarea></td>
  290.           <td>&nbsp;</td>
  291.           <td></td>
  292.         </tr>
  293.         <tr>
  294.           <td height="35"></td>
  295.           <td>&nbsp;</td>
  296.           <td></td>
  297.           <td></td>
  298.           <td></td>
  299.           <td></td>
  300.           <td></td>
  301.           <td></td>
  302.           <td></td>
  303.           <td></td>
  304.         </tr>
  305.         </table>
  306.  
  307.         </FORM>
  308.  
  309.         <? 
  310.  
  311.     } // end if
  312.  
  313. } // end function doForm()
  314.  
  315. // *********** END FUNCTION doForm() *************
  316.  
  317. // *********** START FUNCTION checkForm() *************
  318. function checkForm()
  319. {
  320.     GLOBAL $gbl, $_POST ;
  321.  
  322.  
  323.     $new_user_name = $_POST['new_user_name'];
  324.     $password1 = $_POST['password1'];
  325.     $password2 = $_POST['password2'];
  326.     $email = $_POST['email'];
  327.     $submit = $_POST['submit'];
  328.  
  329.     if ($submit)
  330.     {   if ($new_user_name)
  331.         {   if ( preg_match("/[^0-9a-zA-Z_]/", $new_user_name ) )
  332.             {   $gbl['errors'] .= '• Invalid characters<BR>' ;
  333.                 $new_user_name='';
  334.             }
  335.  
  336.             if ( (strlen($new_user_name) < cnfg('userNameMinLength') )
  337.                  || (strlen($new_user_name) > cnfg('userNameMaxLength') ) )
  338.             {   $gbl['errors'] .= '• Nomes de usuários devem ter menos de ';
  339.                 $gbl['errors'] .= cnfg('userNameMaxLength').', e mais de ';
  340.                 $gbl['errors'] .= cnfg('userNameMinLength').' caracteres.<BR>'; 
  341.             }
  342.  
  343.  
  344.         }
  345.         else
  346.         {   $gbl['errors'] .= '• Você não digitou um nome de usuário.<BR>';
  347.         }
  348.  
  349.  
  350.         if($password1 && $password2)
  351.         {   if($password1 != $password2)
  352.             {   $gbl['errors'] .= '• As senhas digitadas não correspondem uma a outra<BR>';
  353.                 $password1 = ''; 
  354.                 $password2 = '';
  355.             }
  356.  
  357.             if ( (strlen($password1) < cnfg('userPassMinLength') )
  358.                  || (strlen($password1) > cnfg('userPassMaxLength') ) )
  359.             {   $gbl['errors'] .= '• Senhas devem ter menos de ';
  360.                 $gbl['errors'] .= cnfg('userPassMaxLength').', e mais de ';
  361.                 $gbl['errors'] .= cnfg('userPassMinLength').' caracteres.<BR>';
  362.             }
  363.         }
  364.         else
  365.         {   $gbl['errors'] .= '• Você precisa digitar uma senha.<BR>';
  366.             $password1 = ''; 
  367.             $password2 = '';
  368.         }
  369.  
  370.  
  371.         if ($email)
  372.         {   if ( !preg_match("/([\w\-\.])+@([\w\-\.])+\.([a-zA-Z])+/i", $email) )
  373.             {   $gbl['errors'] .= '• Endereço de e-mail inexistente.<BR>';
  374.                 $email = '';
  375.             }
  376.         }
  377.         else
  378.         {   $gbl['errors'] .= '• Você precisa digitar um endereço de email.<BR>';
  379.         }
  380.     } // end if($submit) 
  381.  
  382.  
  383.     if ($gbl['errors'] != '')
  384.     {   return false; 
  385.     }
  386.     else
  387.     {   return true; 
  388.     }
  389.  
  390. } // end function checkForm()
  391.  
  392. // *********** END FUNCTION checkForm() *************
  393.  
  394. ?>
Nov 20 '09 #18
matheussousuke
249 100+
Sleeping again?


XD
Nov 20 '09 #19
Dormilich
8,658 Expert Mod 8TB
@matheussousuke
not yet, but watching 瀬戸の花嫁

do you get any errors? can you find out where your code stops?
Nov 20 '09 #20
matheussousuke
249 100+
@Dormilich

That anime looks hentai, but must be cool.

Well, haven't get any error, the e-mail just doesn't come to inbox.
Nov 20 '09 #21
Atli
5,058 Expert 4TB
This is exactly why we recommend using Swift Mailer, or other such things, because the mail() function is a pain to work with if you are sending anything more complex than a simple plain text message.

It would probably take less time to read up on how to use Swift Mailer than it would trying to get mail() to work properly.

There are two things you could try tho. The headers on lines #139-142 are commented out. Why? One of them is the "Mime-Version" header, which the manual uses in it's HTML example. Try to add that back in, before the "Content-Type" header.

You are also missing the "To: " header from your additional headers.

What does $HTTP_POST_VARS do?
It's the old method to fetch data passed through a HTML <form>, using the POST method. It has now been replaced by $_POST
See the manual entry for $_POST. You should also check out the other superglobals. (To the left on that page.)

@matheussousuke
We don't spend our entire day on here. This is volunteer work we do as well as our day jobs, families, etc..
We can't always (and usually don't) reply within minutes.

But yea, actually. I was sleeping xD
Nov 20 '09 #22
matheussousuke
249 100+
@Atli
Yeah, sure, but sometimes I get a little unsure cause once I posted a post here that got opened, no one answered the questions anymore.


Anyway, thanks for the suport, I'm gonna have to go out now and dont know when I'll have time to go back, maybe on monday. XD

have a nice weekend, and good dreams, here is PM 6:28 XD

Ps: I'll try what u recommended.
Nov 20 '09 #23
matheussousuke
249 100+
Problem solved. It wasn't cause the headers where in portuguese, as Atli said, and because the e-mail newuser@localhost.com configured in another file wasn't being accepted by the siste system, so I had to change to anothe email adress.
Dec 7 '09 #24
matheussousuke
249 100+
I was testing the script and saw a litte thing that could lead me to trouble, I mean, when the user register I'm able to see his password in the mysql database on phpmyadmin, I never saw that before since Im used to see the php scripts passwords being stored as hexadecimal or something like that, but this one leaves it as it is, what can I do?

The script responsible for registration is the same in this topic.
Dec 7 '09 #25
Atli
5,058 Expert 4TB
Passwords are typically stored as hashes. Hashing is a one-way encryption method, which is ideal for storing passwords as you never actually need to see the original. You only need to be able to compare the hash of the original with the hash for what you are testing.

Check out this article. Explains it nicely.

I would recommend avoiding both the MD5 and SHA1 functions, as they have both become relatively weak, and go straight for something stronger, like SHA256 or Whirlpool.

I also strongly recommend using a salt (explained in the article). Anything less than 14 character is to short ;-)
Dec 8 '09 #26
Atli
5,058 Expert 4TB
@matheussousuke
That may not have cause the problem, but using Portuguese headers will have no actual effect. You can include whatever headers you want, and they may be picked up by some clients, but most clients will simply ignore them.

The proper header to set the content type of a message is "content-type". Those exact letters. Mail software doesn't care about the language of the words. It's only sees it as a string of bytes. (The letters are only a visual representation for our benefit.)

Sending a translated version of the words simply means that you have changed the byte string, thus effectively removed the header that sets the content type.

That is not to say some Portuguese clients may not regognize the Portuguese translation. It only means they are operating outside the normal protocol. Relying on that sort of behavior is almost guaranteed to create problems for you.
Dec 8 '09 #27
matheussousuke
249 100+
Everything is in english now, by the way, I'll send u a PM.
Dec 8 '09 #28

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: LRW | last post by:
Because I've had recipients of our newsletter tell us they can't (or won't) receive HTML e-mail, I found out how to make an e-mail that sends both HTML and a plaintext version in a multipart...
10
by: J. Alan Rueckgauer | last post by:
Hello. I'm looking for a simple way to do the following: We have a database that serves-up content to a website. Some of those items are events, some are news articles. They're stored in the...
10
by: Eric Lindsay | last post by:
This may be too far off topic, however I was looking at this page http://www.hixie.ch/advocacy/xhtml about XHTML problems by Ian Hickson. It is served as text/plain, according to Firefox...
0
by: Rey | last post by:
Howdy all. Am using visual web developer 2005 (vb), xp pro sp2. In testing of the system.net.mail to send email from an aspx page where I'm pulling the email contents from a textbox, find that...
6
by: mihirnmehta | last post by:
This is my code function getDetails() { var name = document.getElementById("movie_name").value; if (window.XMLHttpRequest) //For Mozilla Browsers { XMLHttp=new XMLHttpRequest() }
4
by: cybervigilante | last post by:
I sent HTML formatted email, using PHP, to my Yahoo address from my server, and it came out fine, styles and all. I sent it to my gmail address to test it and all I see is the raw html code. But I...
2
by: =?Utf-8?B?Q2FwdGFpbiBEYXZlIQ==?= | last post by:
I wrote some code to send an email with two alternate views: 1) html 2) plain text All the html enabled email clients accept the html just fine and disregard the plain text version. However,...
17
by: V S Rawat | last post by:
I joined this ng and tried to post my first message that had a small php code (HTML and all). my newsserver aioe.net rejected the post saying "HTML Tags". My message was in text format, not in...
2
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.