如何发送HTML电子邮件(PHP)

如何发送HTML电子邮件(PHP),php,email,Php,Email,我有一个php博客系统,用户可以在注册后公开在我们的博客上发表文章,现在我正试图在发布一篇新文章后向我的所有用户发送电子邮件,新的文章名“title example”已经发布 $send = mysqli_query($con, "SELECT * FROM users"); while($em = mysqli_fetch_array($send)) { phpmailer stuff here to = ("$em['email']"); here I'm fetching ev

我有一个php博客系统,用户可以在注册后公开在我们的博客上发表文章,现在我正试图在发布一篇新文章后向我的所有用户发送电子邮件,新的文章名“title example”已经发布

 $send = mysqli_query($con, "SELECT * FROM users");
 while($em = mysqli_fetch_array($send)) {

 phpmailer stuff here

 to = ("$em['email']"); here I'm fetching every email of user
  } while loop is closed here

我想知道这是向所有用户发送电子邮件的正确方式吗?这会导致服务器上出现任何负载吗?

类似的事情会让您开始工作

$headers = "";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: your_from_email_address@yourdomain.com\n";
$headers .= "Organization: yourdomain.com\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-Mailer: PHP". phpversion() ."\n" . PHP_EOL;

$msg_start = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>';
$subj = 'Subject of email';
$msg = $msg_start . '<div style="color:red">This is teh email message right here</div>';

$all_users = mysqli_query($con, "SELECT * FROM users");
while($user = mysqli_fetch_array($all_users)) {
    $e = $user['email'];
    $result = mail($e, $subj, $msg, $headers);

} 
$headers=”“;
$headers.=“内容类型:text/html;字符集=iso-8859-1\n”;
$headers.=“发件人:您的电子邮件”_address@yourdomain.com\n”;
$headers.=“组织:yourdomain.com\n”;
$headers.=“X优先级:3\n”;
$headers.=“X-Mailer:PHP”。phpversion()。“\n”。PHP_EOL;
$msg_start='';
$subj=‘电子邮件主题’;
$msg=$msg\u start'这是一封电子邮件,就在这里;
$all_users=mysqli_query($con,“从用户中选择*);
而($user=mysqli\u fetch\u数组($all\u用户)){
$e=$user['email'];
$result=mail($e、$subj、$msg、$headers);
} 


请注意,对于电子邮件中的HTML,所有样式都必须是内联的。不幸的是,您不能包含像
div{background:wheat;}

这样的HTML标记,这样的东西可以让您开始

$headers = "";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: your_from_email_address@yourdomain.com\n";
$headers .= "Organization: yourdomain.com\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-Mailer: PHP". phpversion() ."\n" . PHP_EOL;

$msg_start = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>';
$subj = 'Subject of email';
$msg = $msg_start . '<div style="color:red">This is teh email message right here</div>';

$all_users = mysqli_query($con, "SELECT * FROM users");
while($user = mysqli_fetch_array($all_users)) {
    $e = $user['email'];
    $result = mail($e, $subj, $msg, $headers);

} 
$headers=”“;
$headers.=“内容类型:text/html;字符集=iso-8859-1\n”;
$headers.=“发件人:您的电子邮件”_address@yourdomain.com\n”;
$headers.=“组织:yourdomain.com\n”;
$headers.=“X优先级:3\n”;
$headers.=“X-Mailer:PHP”。phpversion()。“\n”。PHP_EOL;
$msg_start='';
$subj=‘电子邮件主题’;
$msg=$msg\u start'这是一封电子邮件,就在这里;
$all_users=mysqli_query($con,“从用户中选择*);
而($user=mysqli\u fetch\u数组($all\u用户)){
$e=$user['email'];
$result=mail($e、$subj、$msg、$headers);
} 

请注意,对于电子邮件中的HTML,所有样式都必须是内联的。不幸的是,您不能包含像
div{background:wheat;}
这样的HTML标记