By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,723 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,723 IT Pros & Developers. It's quick & easy.

email address from mysql

ddtpmyra
100+
P: 333
Need help as a newbie I'm trying to create auto email everytime the users execute the button below. Please tell me what wrong with my mail.php file

[PHP]
<html>
<head>


<form action="mail.php" method="POST" enctype="multipart/form-data">

<input type="submit" value="mail now">
</p>
</form>

</body>
</html>
[/PHP]

Here's the PHP email (mail.php) and I don't know how to do it, but I know that my sql is just working fine.

[PHP]
<?php

# Connect to the database
$dbLink = mysql_connect("localhost", "xxx", "xxxxxxxx")
or die("Error! Failed to connect to the MySQL server!");
mysql_select_db("cmr", $dbLink)
or die("Error! Failed to select a database!");

#query
$query="
SELECT m.email, f.approval1
from filestorage f, members m
where f.approved='N'
and f.approval1=m.name


$result = @MYSQL_QUERY($query);

while ($row = mysql_fetch_array ($result)) {
// HTML body
$body = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
$body .= "<i>Your</i> personal photograph to this message.<p>";
$body .= "Sincerely, <br>";
$body .= "PHPMailer List manager";

// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["approval1"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "PHPMailer List manager";

$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["approval1"]);

if(!$mail->Send())
echo "There has been a mail error sending to " . $row["email"] . "<br>";

// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}


?>
[/PHP]
Sep 15 '08 #1
Share this Question
Share on Google+
3 Replies


pbmods
Expert 5K+
P: 5,821
Heya, ddtpmyra.

Where do you initialize $mail?
Sep 15 '08 #2

ddtpmyra
100+
P: 333
I'm totally clueless, can you show me a simple email script that email address comes from mysql or any database?

thanks!
Sep 15 '08 #3

pbmods
Expert 5K+
P: 5,821
You should be pretty close. You'll just need to add something like this:

Expand|Select|Wrap|Line Numbers
  1. $result = @MYSQL_QUERY($query);
  2.  
  3. require_once 'class.phpmailer.php';
  4. $mail = new PHPMailer();
  5.  
  6. while ($row = mysql_fetch_array ($result)) {
  7.  
The require_once() path might change depending on where you keep the PHPMailer class file.
Sep 16 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.