Solved

HTML Mail

Posted on 2003-10-22
4
295 Views
Last Modified: 2010-04-06
I need to create a php program that will let me e-mail everyone i have in a database. I want to e-mail a HTML news letter but i dont know how.

Ta Chris.
0
Comment
Question by:icb01co1
  • 2
4 Comments
 
LVL 10

Expert Comment

by:KenAdney
ID: 9600579
0
 
LVL 1

Expert Comment

by:fyuber
ID: 9603524
http://www.php.net/mail if you wanna do it yourself.
0
 
LVL 2

Accepted Solution

by:
wise0ne earned 50 total points
ID: 9604797
<?

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->From     = "list@mydomain.com";
$mail->FromName = "List manager";
$mail->Host     = "smtp1.site.com;smtp2.site.com";
$mail->Mailer   = "smtp";

@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query  = "SELECT full_name, email, photo FROM employee WHERE id=$id";
$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["full_name"] . ", \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["full_name");
    $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

    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();
}

?>

grab the class file from : http://phpmailer.sourceforge.net/

hope this helps!

0
 
LVL 2

Expert Comment

by:wise0ne
ID: 9604832
<?php

/*
Table Scheme
CREATE TABLE `maillist` (
`id` INT( 3 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 100 ) NOT NULL ,
`email` VARCHAR( 100 ) NOT NULL ,
INDEX ( `id` ) ,
UNIQUE ( `email` )
);

*/

//Connect to Databases
$connection = mysql_connect("localhost", "username", "password") or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><br>SQL Error No.: <b>".mysql_errno()."</b>");

//Select Table
$db = mysql_select_db("dbname", $connection) or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><br>SQL Error No.: <b>".mysql_errno()."</b>");

// Now we can display results.
$sql = "SELECT * FROM maillist";
$sql_result = mysql_query($sql,$connection) or die ("<big>Invalid SQL Query : <b>".mysql_error()."</b><br>SQL Error No.: <b>".mysql_errno()."</b>");

while($row=mysql_fetch_array($sql_result)){
 $to = $row[\"name\"]."<".$row[\"email\"].">";
 
 $headers ="From: webmaster@example.comrn";
 $headers .= "MIME-Version: 1.0rn";
 $headers .= "Content-type: text/html; charset=iso-8859-1rn";
 $subject ="Regarding whatever";
 $body="<html><head></head><body><b>Big Bold HTML Message</b></body></html>";

 // Now we send the message
 //We set a variable equal to the mail() function in order to capture success or fail.
 $send_check=mail($to,$subject,$body,$headers);

 /* It is important to note that while the mail() function will return
 a boolean false if it is unable to pass the message off to be sent.
 This is NOT a guarantee that the message will actually be sent
 or arrive somewhere. When using mail() for real, this checking
 is rarely done. It is included here only for completeness.
 */
 if ($send_check!=true)
 {
 echo 'An error occurred while sending mail.';
 die();
 }
}
?>
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now