本帖最后由 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′”;
即可。结贴。