Page 1 of 1

whats wrong in that code? send an email

Posted: Sun Feb 10, 2008 5:02 pm
by ritinhaa
im trying to send an email...

firstly i need to search the email from the user and im using that code:

***** PLEASE USE THE

Code: Select all

TAG WHEN POSTING *****[/color]

Code: Select all

<?php
ob_start();
 
mysql_select_db($database_ligacaodados, $ligacaodados);    
$sql_util = "SELECT email FROM Utilizador WHERE user='".$_SESSION['MM_Username']."'";
$exe_util = mysql_query($sql_util);
$count=mysql_num_rows($exe_util);
 
        if($count==1){
        
        $rows=mysql_fetch_array($exe_util);
 
        // keep password in $your_password
        $email=$rows['email'];
        
        }
 
 
?>
than im sending it using the email selected:

Code: Select all

<h2>O email foi enviado!
      <?php
 
        
        // ---------------- SEND MAIL FORM ----------------
 
        // send e-mail to ...
        $to=$email;
        
        // Your subject
        $subject="Confirmação de Compra ";
        
        // From
        $header="from: me <myemail@gmail.com>";
        
        // Your message
        $messages= "bla\r\n";
        $messages.="\r\n";
        
        
        // send email
        $sentmail = mail($to,$subject,$messages,$header);
    
              
      ?>
      
      </h2>  
however it isnt working and i wanted to know why.. anyone could help me? i suppose that the error is in the first part because i cant print "$email"... :banghead:

thanks

Re: whats wrong in that code? send an email

Posted: Sun Feb 10, 2008 5:07 pm
by Christopher
Read the page in the manual for the mail() function carefully. It has good examples. Make sure you have the data exactly as in the examples, including line endings.

http://us2.php.net/manual/en/function.mail.php

Re: whats wrong in that code? send an email

Posted: Sun Feb 10, 2008 5:12 pm
by ritinhaa
i suppose the error is when i tried to select the correct email, because when i try to print it... it doesnt appear... so i think it isnt selected nothing at all... :?:
arborint wrote:Read the page in the manual for the mail() function carefully. It has good examples. Make sure you have the data exactly as in the examples, including line endings.

http://us2.php.net/manual/en/function.mail.php

Re: whats wrong in that code? send an email

Posted: Sun Feb 10, 2008 5:26 pm
by califdon
I assume that both the code segments you quoted are part of the same script, right? Have you tested to see that your query does return a result? For example, do you know if your session variable MM_username is set and has a valid value? Have you tried to run the same query outside the script? Those would all be things to do, to narrow the possibilities.

Re: whats wrong in that code? send an email

Posted: Sun Feb 10, 2008 5:33 pm
by ritinhaa
thanks a lot =)

you were right... i was forgoten to use the session... so it couldnt return nothing ;)

Re: whats wrong in that code? send an email

Posted: Sun Feb 10, 2008 6:28 pm
by califdon
ritinhaa wrote:thanks a lot =)
you were right... i was forgoten to use the session... so it couldnt return nothing ;)
I'm sure glad that I never forgot anything! :roll: Glad you found the problem.