如何在php邮件中插入图像? [英] How to insert an image in php mail?

查看:76
本文介绍了如何在php邮件中插入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以php邮件形式插入图像?

How can I insert an image in a php mail form?

我有以下代码:

$headers  = 'MIME-Version: 1.0' . "\n";
        $headers .='Content-Type: text/html; charset="UTF-8"'."\n";
        $headers .='From: text@example.fr';       
        $image = "http://lcda.fr/site/abonnement/img/logo.png";
        //ecriture du message 

        $message .= '<img src=".$image.">';
        $message .= '<p><br/>Votre commande a bien été  enregistrée sous le numéro/ <span style="color:blue">Your command has been successfully recorded under the number :</span> <b>(ref - '.$_SESSION['refvb'].')</b></p>';      
        $message .= '<table width="500">';
        $message .= '<tr><th colspan="2" align="left">Informations abonnement/<span style="color:blue"> Subscription informations</span> :</th></tr>';
        $message .= '<tr><td width="250">Abonnement/<span style="color:blue"> Subscription</span> : </td><td>'.$infoabo['abo'].'</td></tr>';
        $message .= '<tr><td>Durée/<span style="color:blue"> Duration</span> : </td><td>'.$infoabo['duree'].' an(s) </td></tr>';
        $message .= '<tr><td>Quantité/<span style="color:blue"> Quantity</span> : </td><td>'.$infoabo['quantite'].'</td></tr>';
        $message .= '<tr><td>Localisation/<span style="color:blue"> Localisation</span> : </td><td>'.$infoabo['zone'].'</td></tr>';
        $message .= '<tr><td>Prix/<span style="color:blue"> Price</span> : </td><td>'.$infoabo['prix'].' €</td></tr>';  
        $message .= '<tr><td>Commencer l\'abonnement au prochain numéro/<span style="color:blue"> Start the subscription in the next issue</span> : </td><td>'.$startabo.'</td></tr>';  
        $message .= '</table>'; 

        }
        $message .= '<br><p><b>Mode de paiement/<span style="color:blue"> Payment</span> : '.$mode;        
        $message .= '</p>';
        $message .= '';                

        //envoie du mail   
        ini_set("sendmail_from",'test@example.fr');

但图片无法加载?有没有其他方法可以做到这一点?
(重点是将徽标公司放在图像所在的位置)

But the image does not load? Is there any other way to do this? (the point is to put the logo company where the image is placed)

推荐答案

您的图片需要托管在公共网址上,然后在电子邮件中使用

Your image needs to be hosted on an public URL which is then used in the email

例如

$image = 'http://cdn.mydomain.tld/image.png';    

更新:

由swapnesh发布(所以归功于他),你的字符串连接是错误的(虽然他的更正是错误的)所以你的 $ image 路径将不在你的字符串中。

As posted by swapnesh (so credit to him), your string concatenation is wrong (although his correction is wrong) so your $image path won't be in your string.

您需要

// correct
$string = '<img src="'.$image.'">'; //=> <img src="image.png">

// wrong
$string = '<img src=".$image.">'; //=> <img src="$image">

请注意额外的'单引号串。你没有打破字符串来添加变量,并且由于主字符串用单引号括起来,PHP不会解析它以进行插值。

Note the extra ' single quotes in your string. You are not breaking out of the string to add the variable, and as the main string is enclosed in single quotes PHP does not parse it for interpolation.

这篇关于如何在php邮件中插入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆