当我在php中使用mail()时,我收到错误“无法接收”

时间:2010-11-03 07:22:32

标签: php email

$strBody="<TABLE cellSpacing=0 cellPadding=0 align=center border=1><TR><TD align=left valign=top><font face='Verdana, Arial, Helvetica, sans-serif' color='#000000' size=2>Name</font></TD><TD colSpan=2><font face='Verdana, Arial, Helvetica, sans-serif' color='#000000' size='1'>".$_SESSION['fname']."   ".$_SESSION['lname']."</font></TD></TR>";
//$strBody="good".$strBody;
$strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Topic</FONT></TD>";
$strBody=$strBody."<TD colSpan=2 align=left valign=top><font face='Verdana, Arial, Helvetica, sans-serif' color='#000000' size='1'>".$_SESSION['topic']."</font></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Detail of Topic</FONT></TD>";
        $strBody=$strBody."<TD colSpan=2 align=left valign=top><div align=justify><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=1>".$_SESSION['detail']."</FONT></div></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Broad Category</FONT></TD>";
        $strBody=$strBody."<TD colSpan=2 align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=1>".$_SESSION['Head']."</FONT></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Your Educational Level</FONT></TD>";
        $strBody=$strBody."<TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=1>".$_SESSION['reqfor']."</font></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Desired Size</FONT></TD>";
        $strBody=$strBody."<TD align=left valign=top colSpan=2><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=1>".$_SESSION['dsize']." page(s), ".$_SESSION['nofwords']." Words.</font></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Dead Line</FONT></TD>";
        $strBody=$strBody."<TD colSpan=2 align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=1>".$_SESSION['deadline']." (".$_SESSION['deadlinedate'].")</font></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Type/Format</FONT></TD>";
        $strBody=$strBody."<TD colSpan=2 align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=1>".$_SESSION['typeformat']."</font></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Style of Report / Style of Citation</FONT></TD>";
        $strBody=$strBody."<TD colSpan=2 align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=1>".$_SESSION['stylereport']."</font></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Your Email</FONT></TD>";
        $strBody=$strBody."<TD colSpan=2 align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2><a href='mailto:".$_SESSION['email']."'>".$_SESSION['email']."</a></TD></TR>";
        $strBody=$strBody."<TR><TD align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2>Alternate Email</FONT></TD>";
        $strBody=$strBody."<TD colSpan=2 align=left valign=top><FONT face='Verdana, Arial, Helvetica, sans-serif' color=#000000 size=2><a href='mailto:".$_SESSION['aemail']."'>".$_SESSION['aemail']."</a></TD></TR>";
        $strBody=$strBody."<TR><TD colSpan=3></TD></TR></TABLE>";
        $strBody=$strBody."</TABLE></form>";

echo $strBody;
$to= $_SESSION['email'];
$from = "**********";
$subject = "Testing mail";
$message = "Hello! This is a simple email message.";
echo mail($to,$subject,$strBody,$from);

如果我使用$ strBody我得到错误...如果我使用$ message代码工作正常。我显示$ strBody并且显示正常,但是当我尝试在mail()中使用它时,我收到错误。

任何人都可以帮忙。

2 个答案:

答案 0 :(得分:3)

根据PHP Manual for mail(),消息中的行最长为70个字符。并且应该用\ n(LF)分隔。虽然我从未遇到过这样的问题,但你可以尝试一下。

哦,我通常会在单个字符串中写下消息HTML,如:

$message = '
    <div>
        <span>...
        ...etc...
        ';

所以它会自动获得换行符。您可以简单地修剪$strBody=$strBody."部分并将消息连接成一个多行字符串。

如果无法使其正常工作,您可以尝试现成的课程,例如Zend Mail

答案 1 :(得分:0)

$to= $_SESSION['email']; 您确定您的会话包含正确的电子邮件地址吗?尝试调试它。也许你在输出之前忘了session_start