2011-04-14 107 views
0

我已经设置了一个邮件表单来从我的网页发送电子邮件,我希望能够在这些电子邮件中设置图像。这是我目前拥有的代码:将图像放入PHP电子邮件

$to = "[email protected]"; 
$subject = "Emergency details"; 
$body = "Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/".$passport."'/>"; 
if (mail($to, $subject, $body)) { 
    echo("<p>Message successfully sent!</p>"); 
    } else { 
    echo("<p>Message delivery failed...</p>"); 
    } 

当我发这封邮件,输出看起来是这样的:

Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/test.jpg"/> 

,实际上显示的代码,而不是图片。是否有可能让这个显示画面变成图片?

感谢所有帮助

回答

0

您发送此邮件为纯文本。您应该使用mail()的第四个参数(标题)指定它应该被解释为一个html邮件。

示例可在documentation中找到。

的片段:

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Additional headers 
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers .= 'Bcc: [email protected]' . "\r\n"; 
3

那是因为你实际上发送文本邮件,而不是一个HTML邮件。你必须设置正确的标题。

看一看邮件()功能手册:http://php.net/manual/en/function.mail.php

具体做法是:例4中发送HTML邮件

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
0

您发送一个简单的邮件,并且由于这一点,被解释为纯文本。你想要做的是发送一个包含html而不是简单文本的邮件。这要求您在邮件中包含标题,说明邮件的内容。

尝试这种情况:

$headers .= "--$boundary\r\n 
Content-Type: text/html; charset=ISO_8859-1\r\n 
Content-Transfer_Encoding: 7bit\r\n\r\n"; 

$to = "[email protected]"; 
$subject = "Emergency details"; 
$body = "Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/".$passport."'/>"; 
if (mail($to, $subject, $body, $headers)) { 
echo("<p>Message successfully sent!</p>"); 
} else { 
echo("<p>Message delivery failed...</p>"); 
} 

(例如,从http://www.daniweb.com/web-development/php/threads/2959折断)

相关问题