如何在电子邮件php中发送html结构? 下面的代码按原样打印html结构 我想发送链接
$email_message .= "<html><body><a href='http://www.rudraliving.com/brochure_images/$fname'>Download Attachment</a></body></a></html>"."\n\n";
答案 0 :(得分:1)
如果您在localhost上,则必须使用phpmailer库或swiftmailer,要发送html邮件,您必须设置html标头"Content-type:text/html;charset=UTF-8"
例如
<?php
$to = "somebodyelse@example.com";
$message .= "<html><body><a href='http://www.rudraliving.com/brochure_images/$fname'>Download Attachment</a></body></a></html>"."\n\n";>
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'Cc: myboss@example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
答案 1 :(得分:0)
试试这个: more info
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;
//smtp start-----------------------(if u use smtp then uncomment following block)
/* $mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME'; // SMTP username
$mail->Password = 'MANDRILL_APIKEY'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
*/
//smtp end-----------------------
$mail->From = 'from@example.com';
$mail->FromName = 'Your From name';
//set to email
$mail->AddAddress('ellen@example.com','to_name'); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';