【问题标题】:How to send image in PHP mail function如何在 PHP 邮件功能中发送图像
【发布时间】:2023-04-05 17:01:01
【问题描述】:

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

这是我的代码:

<?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;
?>

【问题讨论】:

    标签: php html css email


    【解决方案1】:

    您不能在文本/纯电子邮件上显示图像,如上所示。您必须将其作为 text/html 发送。

    所以你首先必须像这样扩展你的标题:

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

    然后你必须更新你的邮件内容替换\n或用html标签&lt;br&gt;甚至&lt;p&gt;换行

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

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

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

    .

    但更好的方法是使用phpMailer Class

    使用此功能,您将能够在电子邮件中包含任何图像,而无需从任何网站下载。它易于学习且完全可定制。

    顺便说一句:您应该为您的 $body 和 $body2 值使用引号...

    $body= "<<<EOD
    Contact Form Details of $nameFeild
    
    Name: $nameFeild \n
    City: $cityFeild \n
    Country: $countryFeild \n"
    

    【讨论】:

      【解决方案2】:
      $headers  = 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
      
      $message = "<html><head>
      <title>Your email at the time</title>
      </head>
      <body>
      <img src=\"http://www.myserver.com/images_folder/my_image.jpg\">
      </body>"
      mail($email_to, $email_subject , $message,$headers);
      

      【讨论】:

      猜你喜欢
      • 2016-05-22
      • 2016-02-25
      • 2017-08-22
      • 2014-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-18
      • 1970-01-01
      相关资源
      最近更新 更多