将图像放入PHP电子邮件
我已经设置了一个邮件表单,从我的网页发送电子邮件,我希望能够在这些电子邮件中设置图像。这是我目前拥有的代码:将图像放入PHP电子邮件,php,html,ajax,email,Php,Html,Ajax,Email,我已经设置了一个邮件表单,从我的网页发送电子邮件,我希望能够在这些电子邮件中设置图像。这是我目前拥有的代码: $to = "test@test.com"; $subject = "Emergency details"; $body = "Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/".$passport."'/>"; if (mail($to, $subject, $body
$to = "test@test.com";
$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>");
}
$to=”test@test.com";
$subject=“紧急情况详情”;
$body=“护照图片:”;
if(邮件($to$subject$body)){
echo(消息已成功发送!);
}否则{
echo(消息传递失败…);
}
当我发送此电子邮件时,输出如下所示:
Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/test.jpg"/>
护照图片:
并实际显示代码而不是图片。是否可以将此显示改为图片
感谢您的帮助,因为您实际上发送的是文本邮件,而不是HTML邮件。您必须设置正确的标题 请参阅mail()功能手册: 具体来说:示例#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";
这是因为您实际上发送的是文本邮件,而不是HTML邮件。您必须设置正确的标题 请参阅mail()功能手册: 具体来说:示例#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";
您正在以纯文本形式发送此电子邮件。您应该使用mail()的第四个参数(headers)指定将其解释为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";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
//要发送HTML邮件,必须设置内容类型头
$headers='MIME版本:1.0'。“\r\n”;
$headers.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
//附加标题
$headers.='To:Mary,Kelly'。“\r\n”;
$headers.=“发件人:生日提醒”。“\r\n”;
$headers.='Cc:birthdayarchive@example.com' . “\r\n”;
$headers.='密件抄送:birthdaycheck@example.com' . “\r\n”;
您正在以纯文本形式发送此电子邮件。您应该使用mail()的第四个参数(headers)指定将其解释为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";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
//要发送HTML邮件,必须设置内容类型头
$headers='MIME版本:1.0'。“\r\n”;
$headers.='内容类型:文本/html;字符集=iso-8859-1'。“\r\n”;
//附加标题
$headers.='To:Mary,Kelly'。“\r\n”;
$headers.=“发件人:生日提醒”。“\r\n”;
$headers.='Cc:birthdayarchive@example.com' . “\r\n”;
$headers.='密件抄送:birthdaycheck@example.com' . “\r\n”;
您发送的是一封简单的邮件,因此它仅被解释为文本。您要做的是发送包含html而不是简单文本的邮件。这要求您在邮件中包含解释邮件内容的标题
试试这个:
$headers .= "--$boundary\r\n
Content-Type: text/html; charset=ISO_8859-1\r\n
Content-Transfer_Encoding: 7bit\r\n\r\n";
$to = "test@test.com";
$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>");
}
$headers.=“--$boundary\r\n
内容类型:text/html;charset=ISO_8859-1\r\n
内容传输\u编码:7bit\r\n\r\n“;
$to=”test@test.com";
$subject=“紧急情况详情”;
$body=“护照图片:”;
if(邮件($to、$subject、$body、$headers)){
echo(消息已成功发送!);
}否则{
echo(消息传递失败…);
}
(示例摘自)您发送的是一封简单的邮件,因此它仅被解释为文本。您要做的是发送包含html而不是简单文本的邮件。这要求您在邮件中包含解释邮件内容的标题 试试这个:
$headers .= "--$boundary\r\n
Content-Type: text/html; charset=ISO_8859-1\r\n
Content-Transfer_Encoding: 7bit\r\n\r\n";
$to = "test@test.com";
$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>");
}
$headers.=“--$boundary\r\n
内容类型:text/html;charset=ISO_8859-1\r\n
内容传输\u编码:7bit\r\n\r\n“;
$to=”test@test.com";
$subject=“紧急情况详情”;
$body=“护照图片:”;
if(邮件($to、$subject、$body、$headers)){
echo(消息已成功发送!);
}否则{
echo(消息传递失败…);
}
(示例从中截取)