6 Replies - 297 Views - Last Post: 05 September 2017 - 10:36 AM

#1 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

send mail with email addresses from datatbase

Posted 04 September 2017 - 09:34 AM

I get the email addresses from database like this

$q = "SELECT email FROM namen WHERE titel = :id";
$stmt = $db->prepare( $q );
$stmt->execute(array(':id' => $tete));
while( $row = $stmt->fetch() ) {
	
	
	
	echo $row['email']." ; ";
}





My question is, how do I get this into my mail handler so I can send the mail to multiple recipients.



<?php
if(isset($_POST['submit'])){
    $to = "[email protected]";
    $from = $_POST["make_text"];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "DERI";


    $message = $from . " schreef volgend bericht:" . "\n\n" . $_POST['comments'];


    $headers = "From:" . $from;

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

    echo "Mail werd met succes verstuurd.";

   
    }
?>




Can anyone help me please.

Is This A Good Question/Topic? 0
  • +

Replies To: send mail with email addresses from datatbase

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,021
  • Joined: 08-June 10

Re: send mail with email addresses from datatbase

Posted 04 September 2017 - 10:03 AM

I recommend to use a mailing library for that (e.g. http://swiftmailer.org which has a plugin for this use case) since you have to send the email separately for each address (otherwise you tell everyone everyone else’s email address)
Was This Post Helpful? 0
  • +
  • -

#3 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

Re: send mail with email addresses from datatbase

Posted 04 September 2017 - 02:30 PM

Everyone knows everyone else’s email address, so this is not a problem.
I wll have a look at this, thank you.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,021
  • Joined: 08-June 10

Re: send mail with email addresses from datatbase

Posted 04 September 2017 - 02:35 PM

View PostBicklo, on 04 September 2017 - 11:30 PM, said:

Everyone knows everyone else’s email address, so this is not a problem.

Until you have a system where that is not the case and then you will--even unintentionally--forget the importance of privacy.
Was This Post Helpful? 0
  • +
  • -

#5 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

Re: send mail with email addresses from datatbase

Posted 05 September 2017 - 09:33 AM

I know that privacy is very important but it is just something among friends while I try to learn php.
You are right, it's better to learn things as it should from the start.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,481
  • Joined: 12-June 08

Re: send mail with email addresses from datatbase

Posted 05 September 2017 - 09:42 AM

8    echo $row['email']." ; ";

Why not, instead of echoing it, you add to a variable and then use that in the 'to'?

03    $to = "[email protected]";

Was This Post Helpful? 0
  • +
  • -

#7 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

Re: send mail with email addresses from datatbase

Posted 05 September 2017 - 10:36 AM

I think that the problem is because the two parts are on different pages, part one is on mailhandler.php and the other on doener.php.
The form part is on doener.php and $_POST($to) does not work for some reason.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1