【问题标题】:How do I paste a image on a email message如何在电子邮件中粘贴图像
【发布时间】:2014-12-19 20:30:19
【问题描述】:

好吧,这是一个棘手的问题。 (我认为)。 您知道何时收到一条消息,并且电子邮件的页面顶部或底部有图像。 我一直在努力,但无法弄清楚。 我希望你们能帮我解决这个问题。

这是我目前得到的;

    <?php 
    $to = 'info@gmail.com';

    if(isset($_POST['submit']))
    {

    $name = $_POST['name'];
    $gast = $_POST['email'];
    $tmpName = $_FILES['attachment']['tmp_name']; 
    $fileType = $_FILES['attachment']['type']; 
    $fileName = $_FILES['attachment']['name']; 



    if(empty($errors))
    {

    $to = $to;
    $from = $gast;
    $file = fopen($tmpName,'rb'); 
    $data = fread($file,filesize($tmpName)); 
    fclose($file);

    $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";

    $body = "E-mail".
    "Name: $name\n".
    "Email: $gast \n".
    "Content-Type: {$fileType};\n". 
    "Content-Transfer-Encoding: base64\n\n". 
    $data;  

    $headers = "From: $from \r\n";
    $headers .= "Email: $gast \r\n";
    $headers .= "\nMIME-Version: 1.0\n"; 
    $headers .= "Content-Type: multipart/alternative;\n";
    $headers .= " boundary=\"{$mimeBoundary}\""; 
    $headers .= "img src='http://cache.estivant.nl/image/1399025430_12_banners-bestemmingen-single-1680x460-extra2-06-kos_1399025430.jpg' alt='image'";

    $data = chunk_split(base64_encode($data));

    mail($to, $body, $headers);

    }
    }

    ?>


    <html>
    <head></head>
    <body>
    <form method="post" action="">

    <label for="name">name</label>
    <input type="name" name="name" value="" />

    <label for="email">email</label>
    <input type="email" name="email" value="" />

    <button id="submit" name="submit">send</button>
    </form>
    </body>
    </html>

【问题讨论】:

    标签: php html forms email messages


    【解决方案1】:

    只需使用 css 样式编写一个 html 页面并相应地格式化您的电子邮件,然后使用 html 作为您的电子邮件正文。这将在邮件中创建一个图像

    <img src="image.jpg" alt="image"></img>
    

    请注意,只要您不在其信任的发件人列表或联系人列表中,大多数(如果不是全部)电子邮件客户端都会阻止您的图片显示给您的收件人。

    当然,您的电子邮件必须以 html 格式发送

    【讨论】:

      【解决方案2】:

      这是一个带有图片的格式精美的电子邮件示例。

      注意图片语法:&lt;img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" /&gt;'

      $to = 'bob@example.com';
      
      $subject = 'Website Change Request';
      
      $headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
      $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
      $headers .= "CC: susan@example.com\r\n";
      $headers .= "MIME-Version: 1.0\r\n";
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      
      $message = '<html><body>';
      $message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
      $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
      $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>";
      $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
      $message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
      $message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
      $message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
      $addURLS = $_POST['addURLS'];
      if (($addURLS) != '') {
          $message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
      }
      $curText = htmlentities($_POST['curText']);           
      if (($curText) != '') {
          $message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
      }
      $message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
      $message .= "</table>";
      $message .= "</body></html>";
      
      mail($to,$subject,$message,$headers);
      

      代码来源及完整说明:http://css-tricks.com/sending-nice-html-email-with-php/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-05
        • 2015-09-05
        • 1970-01-01
        • 2021-09-27
        相关资源
        最近更新 更多