Page 1 of 1

[solved]mail() values not being sent

PostPosted: 26. April 2012 12:09
by Hamish
Here's a little problem for which I believe the answer is quite simple but maybe I cannot see the wood for the trees:

I have a form which displays data; the user is asked to edit the data which, in turn, updates the database and sends an email with the updated data. The email arrives but although it displays the titles does not display the data.

What am I doing wrong?

Text shown in email:

Name:
Email:
Phone:

php code:
Code: Select all
$email_to = 'someone@here.com';
$name=$row['name'];
$email=$row['email'];
$phone=$row['mobtel'];
$email_subject = 'Feedback from website';
$headers = 'From: someone@there.com\r\n';

$message='Name:  ' .$name. "\r\n". 'Email:  ' .$email. "\r\n". 'Phone:  ' .$phone;


$sent = mail($email_to, $email_subject, $message, $headers);


 if($sent)
 {print "Your mail was sent successfully"; }
 else
 {print "We encountered an error sending your mail"; }


Re: mail() values not being sent

PostPosted: 26. April 2012 15:01
by WilliL
hi Hamish,

just a guess: variables are empty. Try first with echo to screen, check your wql request

Re: mail() values not being sent

PostPosted: 26. April 2012 15:01
by Altrea
Well, there is no line, where your $row array is filled.
Where does this come from?

Re: mail() values not being sent

PostPosted: 26. April 2012 18:51
by Hamish
Guys,

Thanks for your interest.

As you can imagine I have been working at this myself and (with a little help from others) cracked the answer about 1/2 an hour ago: as you have suggested, the answer lies with the 'form code'. First I did a var_dump on the $row values and got a NULL return - obviously they were not being populated. Then I looked at why this might be and, trying one thing after another, came up with the solution that the 'While' loop was the root cause. When I took it ot and ran the code as a function - it all worked!!!

For your info, here is the preceeding code:

Code: Select all
if (isset($_GET['view']))
      {
      $user = sanitizeString($_GET['view']);
      

         
         


   
      
      $data = "SELECT * FROM `qualifications` WHERE email='$user'";
      $result=mysql_query($data) or die(mysql_error());

   while($row=mysql_fetch_array($result)){
   
?>

   <table  style="background-color:#F0F8FF; border='1px'; font-weight: bold;" >

      <caption>Personal Record</caption>
         
   <tr>
   <th>QUAL_ID</th>
      <td><?php
         echo $row['qual_id'];
       ?></td>
   </tr>
   <tr>
   <th>Name</th>
      <td><?php
         echo $row['name'];
         ?></td>
   </tr>
   <tr>
   <th>E-Mail</th>
      <td><?php
         echo $row['email'];
         ?></td>
   </tr>
   <tr>
      <th>Exped</th>
      <td><?php
         echo $row['exped'];
         ?></td>
   </tr>
   
   <tr>
   <th>Main Telephone</th>
      <td><?php
         echo $row['supervisor_cse'];
         ?></td>
   </tr>

   <tr>
   <th>Assessor Cse</th>
      <td><?php
         echo $row['assessor_cse'];
         ?></td>
   </tr>

   <tr>
   <th>Low Level Hills</th>
      <td><?php
         echo $row['lowlevel_hills'];
         ?></td>
   </tr>

   <tr>
   <th>MLT Summer</th>
      <td><?php
         echo $row['mltsummer'];
         ?></td>
   </tr>

   <tr>
   <th>MLT Winterr</th>
      <td><?php
         echo $row['mltwinter'];
         ?></td>
   </tr>

   <tr>
   <th>1st Aid</th>
      <td><?php
         echo $row['firstaid'];
         ?></td>
   </tr>

   <tr>
      <th>Other Quals</th>
         <td><?php
            echo $row['other_quals'];
            ?></td>
      </tr>
   <tr>
      <th>Intro to DoE</th>
         <td><?php
            echo $row['doe_intro'];
            ?></td>
      </tr>
   <tr>
      <th>Disclosure</th>
         <td><?php
            echo $row['disclosure'];
            }
            }
            ?></td>
      </tr>


   </table>
      
               
   <br />
      <form method="post" action="quals.php">
         <input name="Submit1" type="submit" value="Edit" style="width: 67px" /></form>






All I did was remove the 'while' loop and {}s and left the sql-array to run itself and - hey presto - it populated the email $message values.

Don't worry that the email '$message' and the $rows do not match - this is just generic code to get the thing up-and-running. Now I know that all code works I'll build the thing properly.

I am so grateful for your time - I feel certain, from the way you were beginning to look, that you would have come up with this solution too. Thank You.

This can be marked as 'Solved'.

Regards,

'H'