0

i want to send mails using php. for that i have to take mails id from database so i am fetching data from tables and then i am using mail functions but when i am going server and run it then it shows nothing blank page appears site is pligg cms base site

    <html>
    <head>
    <title>Sending HTML email using PHP</title>
    </head>
    <body>
    <?php
    $mysql_host = "localhost";
    $mysql_database = "db";
    $mysql_user = "r";
    $mysql_password = "s#1#";
    $con=mysql_connect($mysql_host,$mysql_user,$mysql_password);
    if(!$con)
    {
          echo "can't connect";
         die("failed connect".mysql_error());

    }
     $db_select=mysql_select_db($mysql_database);
    if(!$db_select)
    {
        echo "db not connected";
    die(" failed user".mysql_error());
   }

   $query1 = "SELECT * FROM  pligg_users"
   $subject = "Exclusive Facebook Cover Offer.";
   $message = "hello";
   $message .= "  <a href='www.getlikeseasy.com'>Read more</a>";
   $message = wordwrap($message,70);
   $headers = "MIME-Version: 1.0" . "\r\n";
   $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
   $results = mysql_query($query1);
   if(!$results) 
    {
    echo "query";
    die(mysql_error());
     }
    while($result_array = mysql_fetch_array($results)) 
     {    
    $c = $result_array['user_email'];
    $retval = mail($c,$subject,$message,$headers);
    if( $retval == true )
    {
        echo .$i." Message sent successfully... to".$c;
        echo "<br>";
    }
    else
    {
        echo .$i." Message could not be sent... to".$c;
        echo "<br>";
    }
    $i++;
}
   echo "email sent";
 ?>
<?php
  mysql_close($con);
 ?> 
 </body>
  </html>
7
  • 2
    Stop using mysql_* functions, they are deprecated stackoverflow.com/questions/12859942/… Commented Mar 28, 2015 at 17:33
  • So what does the error log files of your systems http server say? That is where php errors usually are written to. Commented Mar 28, 2015 at 17:38
  • 2
    @D4V1D that is not the issue here. You should at least mark such comments as "side notes". Commented Mar 28, 2015 at 17:38
  • Are you sure the query gives correct result ? Commented Mar 28, 2015 at 17:39
  • @arkascha That is why I've posted this as a comment and not an answer to his specific problem. Commented Mar 28, 2015 at 17:39

1 Answer 1

2

Blank pages are often the result of syntax errors. I would recommend enabling error reporting so you can be self-sufficient with debugging. I have not worked with PHP for many years now, but I expect this SO post will help: PHP: I get a completely blank page, I don't know how to debug this in PHP

You're missing a semi-colon here:

$query1 = "SELECT * FROM  pligg_users"

I don't know if that will fix all of it but it will definitely help.

Edit:

On the code below you have placed a '.' before echoing a variable on lines 3 and 8, remove those as well.

if( $retval == true )
{
    echo .$i." Message sent successfully... to".$c;
    echo "<br>";
}
else
{
    echo .$i." Message could not be sent... to".$c;
    echo "<br>";
}
Sign up to request clarification or add additional context in comments.

2 Comments

after seeing your post i have correct my mistakes but then also it shows blank page
I have edited my post after discovering two more errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.