如何在PHP邮件功能中发送图像 [英] How to send image in PHP mail function

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

问题描述

我想在邮件中发送图像。如何添加图像,以便它将显示在电子邮件
我想添加图像到客户消息体。
如何在客户端消息体中使用html?

I want to send image in mail.How to add image so that it will show in the email I want to add image to the CLIENT MESSAGE BODY. How to use html in client message body?

这是我的代码:

<?php
/* subject and email varialbles*/

$emailSbuject = 'Enquiry';
$webMaster = 'vivek@a.com';
$emailSbuject2 = 'Thank you';
$client = ' $emailFeild\r\n';
/*gathering data variables*/

$nameFeild = $_POST['name'];
$cityFeild = $_POST['city'];
$countryFeild = $_POST['country'];
$emailFeild = $_POST['email'];
$phoneFeild = $_POST['phone'];
$otherFeild = $_POST['other'];
$questionFeild = $_POST['question'];
$commentFeild = $_POST['comment'];
$phone1Feild = $_POST['phone1'];
$hear1Feild = $_POST['hear1'];
$hear2Feild = $_POST['hear2'];
$hear3Feild = $_POST['hear3'];
$hear4Feild = $_POST['hear4'];
$referralFeild = $_POST['referral'];
$otherhearFeild = $_POST['otherhear'];

// admin message body
$body= <<<EOD
Contact Form Details of $nameFeild

Name: $nameFeild \n
City: $cityFeild \n
Country: $countryFeild \n
Email: $emailFeild \n
Contact Phone: $phoneFeild \n
Other Phone: $otherFeild \n
Question: $questionFeild \n
Comment: $commentFeild \n
Contact Over: $phone1Feild \n
Known Us through: \n

 $hear1Feild
 $hear2Feild
 $hear3Feild
 $hear4Feild
 $referralFeild
 $otherhearFeild
EOD;
// Client message body
$body2 = <<<EOD


Dear $nameFeild



         Thank u for contacting IntaxFin. One of our representatives will contact you the     soonest. If you have more questions or information needed, please let us know. We are happy to serve     you! \n

        -From
         IntaxFin Team \n http://www.intaxfin.com \n

         Like us on Facebook \n         
         Follow us on Twitter \n         
         Connect with us on LinkedIn \n


-------------------------------------------------------------------------------------------------                     e-mail was automatically sent by IntaxFin Administration Directory and is for your reference. Please do not reply to this e-mail address.

Powered by HexCode Technologies Pvt. Ltd.

EOD;
    $headers = "From: $emailFeild\r\n";
    $header = "From: $noreply@intaxfin.com\r\n";
    $success = mail($webMaster,$emailSbuject,$body,$headers);
    $success1 = @mail($emailFeild,$emailSbuject2,$body2,$header);
    /*Result*/


    $theResults = <<<EOD
EOD;

echo  "$theResults";

header("Location: http://www.intaxfin.com/thankyou.html");
exit;
?>


推荐答案

您无法在文字/纯文字电子邮件上显示图片以上。您必须以text / html格式发送。

You cannot display images on text/plain emails as shown above. You must send it as text/html.

因此,您首先必须扩展您的标头,如下所示:

So you first have to extend your headers like this:

$header = "From: $noreply@intaxfin.com\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";

然后您必须更新您的邮件内容,替换 \\\
或具有html标记的换行符< br> 或甚至< p>

Then you must update your mailcontent replacing \n or linebreaks with html tags <br> or even <p>

然后您还可以包含具有您要在电子邮件中显示的图片的图片标签

Then you also can include image tags having the image you want to show in the email

<img src="http://www.yourserver.com/myimages/image1.jpg">

收件人打开时,将从您的网络服务器下载。

This will be downloaded from your webserver when recipient opens it.

但是更好的方法是使用 phpMailer类

BUT the much better way will be to use phpMailer Class

使用此功能,您可以在电子邮件中添加任何图片,无需下载它从任何网站。

Using this, you will be able to include any images IN your email, without need to download it from any website. It is easy to learn and absolutely customizable.

顺便说一下:您应该为$ body和$ body2值使用引号。 。

By the way: You should use quotation marks for your $body and $body2 values...

$body= "<<<EOD
Contact Form Details of $nameFeild

Name: $nameFeild \n
City: $cityFeild \n
Country: $countryFeild \n"

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

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