I get error "Failed to Receive" when i use mail() in php
$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 c开发者_JAVA技巧olSpan=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);
if i use $strBody i get error...if i use $message the code works fine. I have display $strBody and it shows up fine but when i try to use it in mail() i am getting error.
Can anyone please help.
According to the PHP Manual for mail(), the lines in the message must be 70 chars long max. and should be separated with \n (LF). While I've never encountered a problem caused by this, you can give it a try.
Oh, I generally write down message HTML in a single string like:
$message = '
<div>
<span>...
...etc...
';
So it's getting newlines automatically. You can simply trim $strBody=$strBody."
parts and concatenate the message into a single multiline string.
If you can't get it working, you can try ready-made classes like Zend Mail.
$to= $_SESSION['email'];
Are you sure that your session contains correct e-mail address? Try to debug it. Maybe you forgot session_start
before any output?
精彩评论