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

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


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

<input type="submit" value="mail now">


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.


# 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!");

SELECT, f.approval1
from filestorage f, members m
where f.approved='N'

$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"]);

echo "There has been a mail error sending to " . $row["email"] . "<br>";

// Clear all addresses and attachments for next loop

Sep 15 '08 #1
Share this Question
Share on Google+
3 Replies

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

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

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

Sep 15 '08 #3

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);
  3. require_once 'class.phpmailer.php';
  4. $mail = new PHPMailer();
  6. while ($row = mysql_fetch_array ($result)) {
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.