【问题标题】:how to send mail in php with image as body of the mail using PHP Mailer如何使用 PHP Mailer 在 php 中以图像作为邮件正文发送邮件
【发布时间】:2015-06-09 07:41:38
【问题描述】:
$message.="<img src='cf_logo.png'/>";

上面的代码在php中没有显示图片 我需要将图像显示为邮件正文。不是附件。

【问题讨论】:

  • 确保路径正确
  • $message="";我只给了这样的
  • 我想知道路径是否正确......以及您发送邮件的 div 或表格为什么不使用 css 的背景图像属性
  • $message="";图片的路径是对的。我将文件和图像放在同一个文件夹中。好的,我将尝试使用背景图像属性
  • $message.="
    image
    ";我是这样给的。但它仍然没有显示在邮件中

标签: php email sendmail phpmailer


【解决方案1】:

您需要完整路径:

 <img src='add your domain here'/cf_logo.png>

【讨论】:

  • 我给出了完整路径。在 gmail 中显示图像。但在 Outlook 和 Thunderbird 中它不起作用。
【解决方案2】:

试试下面的代码:

$mail = new PHPMailer();

$mail->isSMTP(); // send via SMTP

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;

$mail->Host = $host; //SMTP server
$mail->Port = $port; //set the SMTP port; 587 for TLS
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail

if (strlen($username)) {
    $mail->SMTPAuth = true;
    $mail->Username = $username;
    $mail->Password = $password;
} else {
    $mail->SMTPAuth = false;
}

$mail->From = $from; // FROM EMAIL
$mail->FromName = $fromName; // FROM NAME
$mail->addAddress($to);
$mail->addReplyTo($from);

$mail->IsHTML($html);

$mail->Subject = $subject; // YOUR SUBJECT
$mail->Body = $message; // YOUR BODY
$mail->addAttachment($attachment); // YOUR ATTACHMENT FILE PATH

if ($mail->send()) {
    echo "Message Sent";exit;
} else {
    echo "Message Not Sent<br>";
    echo "Mailer Error: " . $mail->ErrorInfo;exit;
}  

注意:你需要包含php mailer类。

【讨论】:

  • 我包含了 php mailer 类。我不希望将徽标作为附件。我想成为测量的一部分
  • @MeenatchiP 您可以在 $message 中设置带有图像标签的图像。只要确保图像路径正确,它不应该是相对的,你必须设置绝对文件路径,即yoursite/folder/image.jpg
  • 我用我的站点名称给出了整个路径。图像显示在 gmail.Thanks。但在 Outlook 中它不显示图像。
【解决方案3】:

试试这个,它可能会工作。像这样在你的图片网址前面使用 http://

http://yoursite/folder/image.jpg

【讨论】:

    猜你喜欢
    • 2021-02-24
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多