0

Is there a possible way, to insert data from table to mail sending script? I have made this simple script, but it doesnt work. How to mix these 2 codes?

$result = mysql_query("SELECT * FROM tablename WHERE ID =1" ) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo ''. $row['maillist'] .''; }

$to = 'here must be maillist row';  
$subject = 'my subject:';  
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";  
$message = 'html content with img src tag';  

mail($to, $subject, $message, $headers); 

My second question is: If i am using bcc, than gmail or other mail services displaying full code of message with all tags, but not displaying image. So, is there a possible way to fix this problem?

My third question is: If i am inserting image to message (watch the code), then the message appears in SPAM, but if i am using only basic text, than its all normal. How to fix it?

I will be grateful for any answers and help!

user2090528
  • 21
  • 1
  • 4

1 Answers1

0
$q = "SELECT email FROM table WHERE id = '" . $id . "'";
$r = mysql_query($q) or die(mysql_error().'<br />'.$q);
$d = mysql_fetch_assoc($r);

$to = $d['email']:
$subject = 'my subject:';  
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";  
$message = 'html content with img src tag';  

mail($to, $subject, $message, $headers);

If you wanna send email to several people :

$subject = 'my subject:';
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$message = 'html content with img src tag';

$q = "SELECT email FROM table WHERE id = IN (" . $array_ids . ")";
$r = mysql_query($q) or die(mysql_error().'<br />'.$q);
while($row = mysql_fetch_assoc($r)) {
    $to = $row['email']:
    mail($to, $subject, $message, $headers);
}

For the SPAM problem, I'd say try to set you header like this

$headers .= 'Content-type: image/jpeg' . "\r\n";
pistou
  • 2,799
  • 5
  • 33
  • 60
  • in both metods im getting error. I think there is something wrong with this line: $r = mysql_query($q) or die(mysql_error.'
    .$q);
    – user2090528 Feb 28 '13 at 15:54
  • Yep was my bad, now it should be fine – pistou Feb 28 '13 at 16:19
  • Nope, still getting error. Is there a possible way, that the two first lines in my code is bad for mail script? I mean: `include('config.php');` **and** `if(isset($_POST['submit'])) {` – user2090528 Feb 28 '13 at 16:26
  • The php file cant be loaded. I mean, when i pressing submit button, the page not loading. Browser error: HTTP Error 500 (Internal Server Error): The server was attempting to fulfill the request encountered unexpected condition. – user2090528 Feb 28 '13 at 16:36