2012-09-27 52 views
0

我在php上做了电子邮件功能。但是当我收到邮件时没有正确对齐。任何人都可以请帮我解决这个问题。这部分无法正确对齐,我对此没有太多的了解。PHP电子邮件字符对齐

​​
<?php 

    $result = select("SELECT * FROM results 
    ORDER BY userId DESC 
    LIMIT 1"); 
      $row = mysql_fetch_array($result); 


if($row['email']==''){ 
    echo "Email cannot be Send"; 

} 
else{ 

    $mailTo=$row['email']; 
    $name=$row['username']; 
    $score=$row['score']; 
    $to=$mailTo; 

// Your subject 
$subject="Union Assurance Questionnaire Result"; 

// From 
$header="from: Union Assurance<[email protected]>"; 

// Your message 

$message="Dear $name,\r\n"; 
$message.="Thank you For Participate the Union Assurance Questionnaire,\r\n\n"; 
$message.="your Score is: $score "; 
$result2=select("SELECT questions FROM questions"); 
$qstId=1; 


while($row2 = mysql_fetch_array($result2)){ 


    if($row['question'.$qstId.'']=='correct'){ 

$message.="\n\n".$row2['questions'].":"; 
$message.="".$row['question'.$qstId.''].""; 
} 

else{ 


     $message.="\n\n".$row2['questions'].""; 
     $message.= "\t\t".$row['question'.$qstId.''].""; 

    } 
     $qstId++; 
} 

$message.="\n\n Thank you, \n Union Assurance IT Team"; 


// send email 
$sentmail = mail($to,$subject,$message,$header); 

// if your email succesfully sent 
if($sentmail){ 
echo "Email Has Been Sent ."; 
} 
else { 
echo "Cannot Send Email "; 

} 
} 


?> 
+0

您可以将teable-view布局并将其作为html(而不是纯文本)发送。 –

回答

0

发送HTML。 From php.net

$to = '[email protected]'; 

// subject 
$subject = 'Birthday Reminders for August'; 

// message 
$message = ' 
<html> 
<head> 
    <title>Birthday Reminders for August</title> 
</head> 
<body> 
    <p>Here are the birthdays upcoming in August!</p> 
    <table> 
    <tr> 
     <th>Person</th><th>Day</th><th>Month</th><th>Year</th> 
    </tr> 
    <tr> 
     <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> 
    </tr> 
    <tr> 
     <td>Sally</td><td>17th</td><td>August</td><td>1973</td> 
    </tr> 
    </table> 
</body> 
</html> 
'; 

// To send HTML mail, the Content-type header must be set 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 



// Mail it 
mail($to, $subject, $message, $headers);