Solved

HTML Mail

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to count occurrences of each item in an array.

708 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

16 Experts available now in Live!

Get 1:1 Help Now