2015-06-13 48 views
2
function sendEmail($to,$subject,$message,$headers=false){ 
    $from = "[email protected]"; 
    $headers = "From: " . strip_tags($from) . "\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

    try 
    { 
     if(mail($to,$subject, $message, $headers)) 
     { 
      $sentEmail = true; 
     } 
     else 
     { 
      $sentEmail = false; 
     } 
     var_dump($headers); 
    } 
    catch(Exception $ex) 
    { 
     throw new Exception($message, $code, $previous); 
     $sentEmail = false; 
    } 
    return $sentEmail; 
} 

返回false這是我的功能時刪除頁眉 $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 然後郵件發送正常,但如果添加此行郵件功能返回false。 但在本地機器工作正常郵件功能時添加HTML內容類型

請幫忙。 謝謝。

回答

0

我得到的解決方案,現在它的工作,在頭的末尾添加'從'。

function sendEmail($to,$subject,$message,$headers=false){ 
    $from = "[email protected]"; 

    $headers = "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
    $headers .= "From: " . strip_tags($from) . "\r\n"; 
    try 
    { 
     if(mail($to,$subject, $message, $headers)) 
     { 
      $sentEmail = true; 
     } 
     else 
     { 
      $sentEmail = false; 
     } 
     var_dump($headers); 
    } 
    catch(Exception $ex) 
    { 
     throw new Exception($message, $code, $previous); 
     $sentEmail = false; 
    } 
    return $sentEmail; 
}