在编写网络服务时,我如何将图像发送到电子邮件并显示它。我能够发送包含除图像之外的所有内容的电子邮件。我认为图像代码中存在一些错误。任何人都可以帮我解决这个问题吗?我的代码是
<?php
$title=$_REQUEST['title'];
$location=$_REQUEST['location'];
$contactname=$_REQUEST['contactname'];
$contactnumber=$_REQUEST['contactnumber'];
$description=$_REQUEST['description'];
$image=$_REQUEST['image'];
if($title)
{
$Image=basename($_FILES['file']['name']);
$Image=str_replace(' ','|',$Image);
$date=date('YmdHis');
$date=str_replace('%20',' ',$date);
$Image=$date.".jpg";
$tmppath="images/".$Image;
move_uploaded_file($_FILES['file']['tmp_name'],$tmppath);
$message1 = ?><html><head></head><body>
<? $message1 .= ?><img src="http://www.website.com/appinstaller/ramaraju/images/<?= $Image ?>" /></body></html>
<?php
$headers = "From: support@";
$headers .= "Content-type: text/html";
//mail($to, $subject, $message, $headers);
//$mailimg = '<img src="http://www.myappdemo.com/appinstaller/ramaraju/services/images/$file"</a>';
$to = "ramaraju.d@stellentsoft.com";
$subject = "Hi!";
$message="Title : $title\r\n Location:$location\r\n Contact name:$contactname\r\n Contact:$contactnumber\r\n Description:$description\r\n file:$Image";
if (mail($to, $subject, $message, $headers))
{
$message=array("messsage"=>"Message successfully sent!");
} else {
$message=array("message"=>"Message delivery failed.");
}
}
else
{
$message=array("message"=>"provide values");
}
echo json_encode($message);
?>
答案 0 :(得分:1)
您必须执行此<?=$Image ?>
而不是<? $Image ?>
,因为您在src中的代码中没有打印$Image
..
因此,最终的img标签应为
<img src="http://www.myappdemo.com/appinstaller/ramaraju/images/<?=$Image ?>" />
<?
和<?=
被称为短打开标记,并不总是启用(请参阅short_open_tag指令)