如何用PHPMailer发送含图片的HTML格式电子邮件?

更新于
2026-09-26 03:59:56
2阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计178个文字,预计阅读时间需要1分钟。

如何用PHPMailer发送含图片的HTML格式电子邮件?

phprequire 'class.phpmailer.php';$mail=new PHPMailer();$mail->IsSMTP();$mail->Host='smtp1.example.com;smtp2.example.com';$mail->SMTPAuth=true;$mail->Username='smtpusername';$mail->Password='smtppassword';

<?php require("class.phpmailer.php"); $mail = new PHPMailer();$mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp1.example.com;smtp2.example.com"; $mail->SMTPAuth = true; $mail->Username = 'smtpusername'; $mail->Password = 'smtppassword'; $mail->From="[emailprotected]"; $mail->FromName="My site's mailer"; $mail->Sender="[emailprotected]"; $mail->AddReplyTo("[emailprotected]", "Replies for my site"); $mail->AddAddress("[emailprotected]"); $mail->Subject = "Test 1"; $mail->IsHTML(true); $mail->AddEmbeddedImage('logo.jpg', 'logoimg', 'logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg $mail->Body = "<h1>Test 1 of PHPMailer html</h1> <p>This is a test picture: <img src=\"cid:logoimg\" /></p>"; $mail->AltBody="This is text only alternative body."; if(!$mail->Send()) { echo "Error sending: " . $mail->ErrorInfo;; } else { echo "Letter is sent"; } ?>

如何用PHPMailer发送含图片的HTML格式电子邮件?
标签:html

本文共计178个文字,预计阅读时间需要1分钟。

如何用PHPMailer发送含图片的HTML格式电子邮件?

phprequire 'class.phpmailer.php';$mail=new PHPMailer();$mail->IsSMTP();$mail->Host='smtp1.example.com;smtp2.example.com';$mail->SMTPAuth=true;$mail->Username='smtpusername';$mail->Password='smtppassword';

<?php require("class.phpmailer.php"); $mail = new PHPMailer();$mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp1.example.com;smtp2.example.com"; $mail->SMTPAuth = true; $mail->Username = 'smtpusername'; $mail->Password = 'smtppassword'; $mail->From="[emailprotected]"; $mail->FromName="My site's mailer"; $mail->Sender="[emailprotected]"; $mail->AddReplyTo("[emailprotected]", "Replies for my site"); $mail->AddAddress("[emailprotected]"); $mail->Subject = "Test 1"; $mail->IsHTML(true); $mail->AddEmbeddedImage('logo.jpg', 'logoimg', 'logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg $mail->Body = "<h1>Test 1 of PHPMailer html</h1> <p>This is a test picture: <img src=\"cid:logoimg\" /></p>"; $mail->AltBody="This is text only alternative body."; if(!$mail->Send()) { echo "Error sending: " . $mail->ErrorInfo;; } else { echo "Letter is sent"; } ?>

如何用PHPMailer发送含图片的HTML格式电子邮件?
标签:html