1

在编写网络服务时,我如何将图像发送到电子邮件并显示它。我能够发送包含除图像之外的所有内容的电子邮件。我认为图像代码中有一些错误。任何人都可以帮我解决这个问题吗?我的代码是

<?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);



?>
4

1 回答 1

1

您必须这样做,<?=$Image ?>而不是<? $Image ?>像在 src 中的代码中那样,您还没有打印$Image..

因此最终的 img 标签应该是

<img src="http://www.myappdemo.com/appinstaller/ramaraju/images/<?=$Image ?>" />

<?并被<?=称为短开放标签,并不总是启用(参见short_open_tag指令)

于 2012-04-23T06:02:47.177 回答