[solved]mail() values not being sent

Problems with the Windows version of XAMPP, questions, comments, and anything related.

[solved]mail() values not being sent

Postby Hamish » 26. April 2012 12:09

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"; }

Hamish
 
Posts: 15
Joined: 18. June 2011 21:21
Operating System: Windows 7

Re: mail() values not being sent

Postby WilliL » 26. April 2012 15:01

hi Hamish,

just a guess: variables are empty. Try first with echo to screen, check your wql request
Willi
WilliL
 
Posts: 661
Joined: 08. January 2010 10:54
Operating System: Win7Home Prem 64 SP1

Re: mail() values not being sent

Postby Altrea » 26. April 2012 15:01

Well, there is no line, where your $row array is filled.
Where does this come from?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8294
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: mail() values not being sent

Postby Hamish » 26. April 2012 18:51

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'
Hamish
 
Posts: 15
Joined: 18. June 2011 21:21
Operating System: Windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 68 guests