douben7260 2014-10-17 11:21
浏览 65
已采纳

如何在PHP邮件功能中发送图像

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?

Here is my code :

<?php
/* subject and email varialbles*/

$emailSbuject = 'Enquiry';
$webMaster = 'vivek@a.com';
$emailSbuject2 = 'Thank you';
$client = ' $emailFeild
';
/*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 

City: $cityFeild 

Country: $countryFeild 

Email: $emailFeild 

Contact Phone: $phoneFeild 

Other Phone: $otherFeild 

Question: $questionFeild 

Comment: $commentFeild 

Contact Over: $phone1Feild 

Known Us through: 


 $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! 


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


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



-------------------------------------------------------------------------------------------------                     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
";
    $header = "From: $noreply@intaxfin.com
";
    $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;
?>
  • 写回答

2条回答 默认 最新

  • doudou0111 2014-10-17 12:01
    关注

    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
    MIME-Version: 1.0
    Content-Type: text/html; charset=utf-8
    ";
    

    Then you must update your mailcontent replacing 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.

    .

    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.

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

    $body= "<<<EOD
    Contact Form Details of $nameFeild
    
    Name: $nameFeild 
    
    City: $cityFeild 
    
    Country: $countryFeild 
    "
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算