?
Solved

HTML Mail

Posted on 2003-10-22
4
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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 receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

765 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