• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

如果把变量 echo后的内容存储在一个变量里呢?

php 搞代码 4年前 (2022-01-23) 13次浏览 已收录 0个评论
文章目录[隐藏]

本帖最后由 u011552243 于 2013-08-20 20:08:40 编辑

php echo email

问题背景:我想输出一个表格,并且把这个表格作为内容发email出去。
问题:先上代码,

 $message = '<table><tr><td><p>'; $message.= 'Driver:  '; $message.= $firstName.'  '.$lastName; $message.= '</p></td></tr><tr><td><p>Date:'.$orderTime.'</p></td></tr></table><table><tr><td><p>No: 1</p></td><td><p>Car'.$truck.':'.'     '.$licNum; $message.= '</p></td></tr><tr><td><p>Kund:'.$customerName.'</p></td><td><p>Order:'.$orderNum.'</p></td></tr><tr><td><p>'; $message.= 'Book number:'.$bookNumPick.'</p></td><td><p>Produktnamn:'.$productName.'</p></td></tr><tr><td><p>Chassi:'; $message.=  $tankName.'</p></td><td><p>Tank number:'.$chassi.'</p></td></tr><tr><td><p>Place:'.$locationPick.'</p></td><td><p>Place 2:'; $message.=  $portCodePick.'</p></td> </tr><tr><td><p>Place 3:'.$locationUnload.'</p></td><td><p>Place 4:'; $message.=  $timeUnload.'</p></td></tr><tr><td><p>Place 5:'.$ADRclass.'</p></td><td><p>Place 5:'.$weight.'</p></td></tr><tr><td><p>Place 6:'; $message.=  $locationLoad.'</p></td><td><p>Place 7:'.$loadTime.'</p></td></tr><tr><td colspan="2"><p>Place 8:'; $message.=  '</p></td></tr><tr><td colspan="2"><p>'.$info.'</p></td></tr><tr><td><p>Place 9:'.$outE.'</p></td><td><p>Place 10:'.$bookNumOut.'</p></td></tr><tr> <td><p>Place 11:'; $message.=  $portCodeOut.'</p></td><td></td></tr></table>'; echo $message."<br>"; $to = $email; $subject = "Task"; $from = EMAIL; $headers = "From: $from"; echo $headers."<br>";  mail($to,$subject,$message,$headers);

说明一下,一开始我用双引号的,后来为了保证$message里的内容保持双引号,就把外面的双引号改成单引号了。

事实上,我希望email的内容是echo $message的结果。但用mail()函数直接把$message发送出去,接收到的结果是:

。。。。(当中省略,可见$message)。。。。。

直接就是把$message里面的内容直接发送出去,而不是把echo $message 后结果传出去。
怎么办?
方便的话,可否指点关键代码片段或者示例,非常感谢。

回复讨论(解决方案)

问题背景:我想输出一个表格,并且把这个表格作为内容发email出去。
问题:先上代码,

 $message = '<table><tr><td><p>'; $message.= 'Dri<b style="color:transparent">来&源gao@dai!ma.com搞$代^码%网</b><img>搞gaodaima代码</img>ver:  '; $message.= $firstName.'  '.$lastName; $message.= '</p></td></tr><tr><td><p>Date:'.$orderTime.'</p></td></tr></table><table><tr><td><p>No: 1</p></td><td><p>Car'.$truck.':'.'     '.$licNum; $message.= '</p></td></tr><tr><td><p>Kund:'.$customerName.'</p></td><td><p>Order:'.$orderNum.'</p></td></tr><tr><td><p>'; $message.= 'Book number:'.$bookNumPick.'</p></td><td><p>Produktnamn:'.$productName.'</p></td></tr><tr><td><p>Chassi:'; $message.=  $tankName.'</p></td><td><p>Tank number:'.$chassi.'</p></td></tr><tr><td><p>Place:'.$locationPick.'</p></td><td><p>Place 2:'; $message.=  $portCodePick.'</p></td> </tr><tr><td><p>Place 3:'.$locationUnload.'</p></td><td><p>Place 4:'; $message.=  $timeUnload.'</p></td></tr><tr><td><p>Place 5:'.$ADRclass.'</p></td><td><p>Place 5:'.$weight.'</p></td></tr><tr><td><p>Place 6:'; $message.=  $locationLoad.'</p></td><td><p>Place 7:'.$loadTime.'</p></td></tr><tr><td colspan="2"><p>Place 8:'; $message.=  '</p></td></tr><tr><td colspan="2"><p>'.$info.'</p></td></tr><tr><td><p>Place 9:'.$outE.'</p></td><td><p>Place 10:'.$bookNumOut.'</p></td></tr><tr> <td><p>Place 11:'; $message.=  $portCodeOut.'</p></td><td></td></tr></table>'; echo $message."<br>"; $to = $email; $subject = "Task"; $from = EMAIL; $headers = "From: $from"; echo $headers."<br>";  mail($to,$subject,$message,$headers);

说明一下,一开始我用双引号的,后来为了保证$message里的内容保持双引号,就把外面的双引号改成单引号了。

事实上,我希望email的内容是echo $message的结果。但用mail()函数直接把$message发送出去,接收到的结果是:

。。。。(当中省略,可见$message)。。。。。

直接就是把$message里面的内容直接发送出去,而不是把echo $message 后结果传出去。
怎么办?
方便的话,可否指点关键代码片段或者示例,非常感谢。

自己解决了。其中, $headers = “From: $from”. “\r\n”;;
$headers .= “MIME-Version: 1.0\n” . “Content-type: text/html; charset=UTF-8′”;
即可。结贴。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如果把变量 echo后的内容存储在一个变量里呢?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址