Php 以html格式发送邮件正文 $site=”http://127.0.0.1/website"; $webmaster=“”; $to=“$email”; $subject=“您的新密码”; $message=“

Php 以html格式发送邮件正文 $site=”http://127.0.0.1/website"; $webmaster=“”; $to=“$email”; $subject=“您的新密码”; $message=“,php,html,email,smtp,Php,Html,Email,Smtp,您好。您的密码已重置。您的新密码如下所示:密码:$pass”; $host=“smtp.live.com”; $port=“587”; $eusername=”email@hotmail.com"; $epassword=“密码!”; $headers=array('From'=>$webmaster,'To'=>$To,'Subject'=>$Subject,'MIME Version:1.0','C

您好。您的密码已重置。您的新密码如下所示:
密码:$pass



”; $host=“smtp.live.com”; $port=“587”; $eusername=”email@hotmail.com"; $epassword=“密码!”; $headers=array('From'=>$webmaster,'To'=>$To,'Subject'=>$Subject,'MIME Version:1.0','Content type:text/html;charset=iso-8859-1'); $smtp=@Mail::factory('smtp', 数组('host'=>$host,'port'=>$port,'auth'=>true,'username'=>$eusername,'password'=>$epassword)); $mail=@$smtp->send($to、$headers、$message); 如果(@PEAR::isError($mail)){ echo(“”$mail->getMessage()”

”; }否则{ echo“您的密码已重置。已将您的新密码发送到$email的电子邮件”; }
上面的代码应该是用html向某人发送电子邮件。我已经尝试了很长一段时间,但我没有取得任何进展。如果有人能帮我的话。那太棒了。

您还需要使用Mail/mime并设置邮件的HTML版本。Pear有一个这样的例子



Hi,什么东西不起作用?当它到达电子邮件时,你可以看到html标记。例如,请参阅。也许你应该去掉一些消息PHP代码并尝试运行它。这样你可以缩小你的问题范围。我开始只是做标记,但那也不起作用。
$site = "http://127.0.0.1/website";                                             
$webmaster = "<email@hotmail.com>";
$to = "$email";                                             
$subject = "Your new password";
$message = "<html><body><p>Hello. Your password has been reset. Your new password is bellow</p><br/><p>Password : $pass</p><br/><a href='$site/activatePass.php?user=$user&password=$pass&code=$dbcode'>Acrivate</a><br/></body></html>";
$host = "smtp.live.com";                                                
$port = "587";                                              
$eusername = "email@hotmail.com";                                               
$epassword = "password!";                                               
$headers = array ('From' => $webmaster,'To' => $to,'Subject' => $subject, 'MIME-Version: 1.0', 'Content-type: text/html; charset=iso-8859-1');                                              
$smtp =@ Mail::factory('smtp',                                                
array ('host' => $host,'port' => $port,'auth' => true,'username' => $eusername,'password' => $epassword));                                              
$mail = @$smtp->send($to, $headers, $message);                                                                                                  
if (@PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
 echo "Your password has been reset. An email has been sent with your new password to $email";
 }
<?php

include 'Mail.php';
include 'Mail/mime.php' ;

$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = '/home/richard/example.php';
$crlf = "\n";
$hdrs = array(
              'From'    => 'you@yourdomain.com',
              'Subject' => 'Test mime message'
              );

$mime = new Mail_mime(array('eol' => $crlf));

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('postmaster@localhost', $hdrs, $body);

?>