在电子邮件脚本中发送html结构


Send html structure in email script

如何在电子邮件php中发送html结构?下面的代码按原样打印html结构我想发送链接

$email_message .= "<html><body><a href='http://www.rudraliving.com/brochure_images/$fname'>Download Attachment</a></body></a></html>"."'n'n";

如果您在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);
?>

试试这个:更多信息

    <?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';