如何使用PHPMailer在电子邮件中发送图像

时间:2014-11-15 09:55:34

标签: php image email phpmailer

我是PHP的新手,我希望使用PHPMailer发送用户从他/她的计算机上传的图像。 请用不同的文件举例说明。

file1.php

  < input type="file" id="lcimage" name="image" />

file2.php

 $LC = $_POST['image'];
    $mail->AddEmbeddedImage($LC, 'lcimage', $LC);
    <img src="" />

2 个答案:

答案 0 :(得分:2)

文件类型元素未添加到$ _POST变量中。 上传文件有一个不同的超级全局可用,即$ _FILES

首先,请确保在表单中添加了enctype =“multipart / form-data”属性 否则,$ _FILES

中将不会收到上传的文件元素
    <form method="post" action="process.php" enctype="multipart/form-data">
       <input type="file" id="lcimage" name="image" />
    </form>

要在电子邮件中添加此文件,您可以使用此代码。

$mail->AddAttachment($_FILES['image']['tmp_name'],
                         $_FILES['image']['name']);

答案 1 :(得分:0)

使用此.. ..

$mail->IsHTML(true);
$mail->AddEmbeddedImage('logo.jpg', 'logoimg');
$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test picture: <img src=\"cid:logoimg\" /><img src=\"cid:logo2img\" /></p>";

希望这会对你有所帮助

相关问题