2012-07-29 3 views
0

hes 이메일을 입력 한 곳에서 비밀번호 재설정 페이지를 만들었습니다. 그러면 PHP에서 재설정 키를 보냅니다. 메일은 작동하지만 Gmail 계정에 일반 텍스트로 표시됩니다. 나는 그것이 HTML로 가기를 원했다.PHP HTML 메일이 원하는대로 작동하지 않습니다.

$subject = "Your password reset for {$config['site_name']}"; 

$message = "<html><body>"; 

$message .= "<p>Someone on" . $config['site_domain'] . "tried to reset your password.</p>"; 
$message .= "<p>Please click below link, if you want to reset your password.</p>"; 

$message .= "<p><a href='" . $config['site_url'] . "/forgot_password.php?key=" . $key . "'>" . $config['site_url'] . "/forgot_password.php?key=" . $key . "</a></p>"; 


$message .= "<p>Thank you,<br>The Admin - " . $config['site_url'] . " </p>"; 

$message .= "</body></html>"; 

// Create email headers    
// 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"; 

// Additional headers 
//$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
$headers .= "From: " . $config['site_name'] . " <[email protected]" . $config['site_domain'] . "> \r\n"; 
$headers .= "X-Sender: <[email protected]" . $config['site_domain'] . "> \r\n"; 
$headers .= "Reply-To: <[email protected]" . $config['site_domain'] . "> \r\n"; 

mail($input['email'],$subject,$message,$headers); 

//update pw_reset field into DATABASE 
$stmt = $mysqli->prepare("UPDATE members SET pw_reset = ? WHERE email = ?"); 
$stmt->bind_param("ss", $key, $input['email']); 
$stmt->execute(); 
$stmt->close();  
+1

다른 이메일 제공 업체는 어떻습니까? –

+0

개인적으로 나는'Zend_Mail'을 좋아합니다. 필요한 모든 일을 다 했습니까? –

+0

나는 phpmailer를 좋아한다. 자동으로 멀티 파트 전자 메일 메시지를 생성합니다. 일반 메일()을 사용하는 경우 헤더 및 구분 기호를 직접 써야합니다. P (일반 텍스트를 가져 오기 위해 설정된 사람에게 HTML 이메일을 보내지 않으므로 멀티 파트를 수행해야합니다.) – octern

답변

1

이처럼 헤더를 구성해야합니다

$headers = 'From: You <[email protected]>' . "\n"; 
$headers .= 'MIME-Version: 1.0' . "\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

공지 사항을이 MIME 전에이며, 콘텐츠 및 전용 콘텐츠 "\ 연구 \ n을"로 끝에서 다른 단지 것을 "\ 엔".

Source (saganwebdesign)

0

하면이 기능을 사용해보십시오. 성공시 true를 반환합니다.

function sendMail($email, $subject, $message) 
{ 
    $supportEmail = '[email protected]'; 
    $from = 'Test Application'; 
    $msg = $message; 
    $from = str_replace(' ', '-', $from); 
    $frm = $from.' <'.$supportEmail.'>'; 
    preg_match("<(.*)@(.*\..*)>", $frm, $match); 

    ///////////////////Headers///////////////// 
    $hdr=''; 
    $hdr.='MIME-Version: 1.0'."\n"; 
    $hdr.='content-type: text/html; charset=iso-8859-1'."\n"; 
    $hdr.="From: {$frm}\n"; 
    $hdr.="Reply-To: {$frm}\n"; 
    $hdr.="Message-ID: <".time()."@{$match[2]}>\n"; 
    $hdr.='X-Mailer: PHP v'.phpversion(); 
    [email protected]($email, $subject, $msg, $hdr); 
    if($x==0) 
    { 
     $email=str_replace('@','\@', $email); 
     $hdr=str_replace('@','\@',$hdr); 
     [email protected]($email, $subject, $msg, $hdr); 
    } 
    return $x; 
} 
관련 문제