Jump to content

Recommended Posts

Hello everyone.

 

I have a problem with my php code, where I placed in hosting server. Everything works fine, my database,registration system(where I getting users names and emails to my database), even in this code, I'm recieving a message where I coded to message me that function "mail_body", is sent to the registered users(When I check registered user email, there is nothing(no email from this php system)). There are two problems , when I active this php file, I'm getting those two errors (below my text). If someone could help me, I would be truly grateful for such a help.

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a1848137/public_html/newsletter.php on line 6

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1848137/public_html/newsletter.php on line 8

 



<?php


include_once "connect_to_mysql.php";
    
$sql = mysql_query("SELECT * FROM newsletter WHERE received='0' LIMIT 20");
$numRows = mysql_num_rows($sql);
$mail_body = '';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
    $name = $row["name"];
$email = $row["email"];




    $mail_body = '<html>
<body style="background-color:#676666; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;">
<h3 style="color:EE0000"><a href="http://pc123.com"><img src="img/baltas logo.png" alt="PC123.com" width="230" height="80" border="0"></a> Newsletter
</h3>
<p>Hi !' . $name . ',</p>
<p>Text about something</p>
<p>Testing</p>
<hr>
<p>u can refuse our <a href="/unregister/opt_out.php' . $email . '">clicking here</a> newsletter</p>
</body>
</html>';
    $subject = "PC newsletter";
    $headers  = "From:PC123.com\r\n";
    $headers .= "Content-type: text/html\r\n"; 
    $to = "$email";


    $mail_result = mail($to, $subject, $mail_body, $headers);


if ($mail_result) {
mysql_query("UPDATE newsletter SET received='1' WHERE email='$email' LIMIT 1");
} else {
  
}


}
?>
<?php


if ($numRows == 0) {


$subj = "Newsletters had been sent";
$body = "Newsletters had been sent";
     $hdr .= "Content-type: text/html\r\n"; 
     mail("myemail@gmail.com", $subj, $body, $hdr);


}


?>

Edited by mac_gyver
code tags around posted code please

Well, don't assume your query actually runs before continuing on. See the very first example in the documentation for mysql_query() for how to detect query errors. Also notice the big pink notice at the top of the page that says that the mysql extension is deprecated and will be removed from PHP soon. Best not to use it if you want your code to run in the future.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.