Solved

HTML Mail

Posted on 2003-10-22
4
293 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP radio buttons with email not sending 24 94
Contact Forms for Website 6 78
Lines Not Lining Up 2 62
Windows Tool to Build Android and iOS App 3 53
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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 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

21 Experts available now in Live!

Get 1:1 Help Now