whats wrong in that code? send an email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ritinhaa
Forum Newbie
Posts: 3
Joined: Sun Feb 10, 2008 4:58 pm

whats wrong in that code? send an email

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: whats wrong in that code? send an email

Post 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
(#10850)
ritinhaa
Forum Newbie
Posts: 3
Joined: Sun Feb 10, 2008 4:58 pm

Re: whats wrong in that code? send an email

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: whats wrong in that code? send an email

Post 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.
ritinhaa
Forum Newbie
Posts: 3
Joined: Sun Feb 10, 2008 4:58 pm

Re: whats wrong in that code? send an email

Post by ritinhaa »

thanks a lot =)

you were right... i was forgoten to use the session... so it couldnt return nothing ;)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: whats wrong in that code? send an email

Post 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.
Post Reply