2010-04-11 6 views
0

이 코드를 사용하려고하지만 처리하지 않고 오류를 출력하지 않습니다.PHP 메일 전송 코드가 작동하지 않습니다.

function send_email($subject='Activate Your Account', $html_content, $text_content, $headers) { 

    $en['email'] = '[email protected]'; 
    $to = $en['email']; 
    $en['memb_id'] = '39'; 
    $en['confcode'] = '69696969'; 
    $en['user'] = 'couple'; 

    $text_content = "Confirm Your domain.com Account\r\n"; 
    $text_content.= "UserName: " . $en['user'] . "\r\n"; 
    $text_content.= "Activate Your Account by visiting this link below:\r\n"; 
    $text_content.= "http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "\r\n"; 
    $text_content.= "\r\n"; 
    $text_content.= "______________________\r\n"; 
    $text_content.= "Thanks,\r\n"; 
    $text_content.= "Staff"; 

    $html_content = "<html><body><h1>Confirm Your domain.com Account</h1>"; 
    $html_content.= "<p>UserName: " . $en['user'] . "<br>"; 
    $html_content.= "Activate Your Account by visiting this link below:<br>"; 
    $html_content.= "<a href=http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . ">http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "</a>"; 
    $html_content.= "</p>"; 
    $html_content.= "______________________<br>"; 
    $html_content.= "Thanks,<br>"; 
    $html_content.= " Staff"; 
    $html_content.= "</body></html>"; 

    $mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x'; 

    $headers = "MIME-Version: 1.0\r\n"; 
    $headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n"; 
    $headers.= "Content-Transfer-Encoding: 7bit\r\n"; 

    $body = "This is a multi-part message in mime format.\n\n"; 
    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $text_content; 
    $body.= "\n\n"; 

    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/html; charset=\"UTF-8\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $html_content; 
    $body.= "\n\n"; 
    $body.= "--$mime_boundary--\n"; 

    $headers.= 'From: <[email protected]>' . "\r\n"; 
    $headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n"; 
    $headers.= 'Date: '.date('n/d/Y g:i A')."\r\n"; 
    $headers.= 'Reply-To: <[email protected]>' . "\r\n"; 

    return mail($to, $subject, $body, $headers); 
    echo $to; 
    echo $subject; 
    echo $body; 
    echo $headers; 
    } 
+2

서버에 메일 서버가 구성되어 있습니까? 그렇지 않다면 그것은 문제입니다. – Ben

+1

무엇을하고 있는지 자세히 설명해 줄 수 있습니까? –

+0

+1 둘 다. –

답변

2

마지막 비트는 나를 혼동했습니다

return mail($to, $subject, $body, $headers); 
echo $to; 
echo $subject; 
echo $body; 
echo $headers; 

당신은 그 echo 문 아무도 그들이 return 직후이기 때문에 실행 얻을 것 없는지 알아?

error_log을 사용해보십시오. 시도하지 않은 경우 스크립트의 단계를 확인하거나 오류 로그 자체를 확인하십시오.

+0

내 error_log가 사용 중입니다. 켜져 있지만 출력 오류는 없다. – acctman

1

PHPMailer/Lite을 사용하십시오. MIME 두통을 스스로 해결하십시오.

require_once('../class.phpmailer.php'); 

$mail    = new PHPMailer(); // defaults to using php "mail()" 

$body    = file_get_contents('contents.html'); 
$body    = eregi_replace("[\]",'',$body); 

$mail->AddReplyTo("[email protected]","First Last"); 

$mail->SetFrom('[email protected]', 'First Last'); 

$mail->AddReplyTo("[email protected]","First Last"); 

$address = "[email protected]"; 
$mail->AddAddress($address, "John Doe"); 

$mail->Subject = "PHPMailer Test Subject via mail(), basic"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$mail->MsgHTML($body); 

$mail->AddAttachment("images/phpmailer.gif");  // attachment 
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
1

여기서는 수정했습니다. 나는 그것을 점검하고 잘 작동하고있다. 또한 호스팅에서 mail() 기능을 지원하는지 확인하십시오. SMTP가 활성화되어 있지 않으면 메일을 확실히 보낼 수 없을 것입니다.

개정 CODE : 도움이

<?php 
function send_email($subject='Activate Your Account') { 

    $en['email'] = '[email protected]'; 
    $to = $en['email']; 
    $en['memb_id'] = '39'; 
    $en['confcode'] = '69696969'; 
    $en['user'] = 'couple'; 

    $text_content = "Confirm Your domain.com Account\r\n"; 
    $text_content.= "UserName: " . $en['user'] . "\r\n"; 
    $text_content.= "Activate Your Account by visiting this link below:\r\n"; 
    $text_content.= "http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "\r\n"; 
    $text_content.= "\r\n"; 
    $text_content.= "______________________\r\n"; 
    $text_content.= "Thanks,\r\n"; 
    $text_content.= "Staff"; 

    $html_content = "<html><body><h1>Confirm Your domain.com Account</h1>"; 
    $html_content.= "<p>UserName: " . $en['user'] . "<br>"; 
    $html_content.= "Activate Your Account by visiting this link below:<br>"; 
    $html_content.= "<a href=http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . ">http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "</a>"; 
    $html_content.= "</p>"; 
    $html_content.= "______________________<br>"; 
    $html_content.= "Thanks,<br>"; 
    $html_content.= " Staff"; 
    $html_content.= "</body></html>"; 

    $mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x'; 

    $headers = "MIME-Version: 1.0\r\n"; 
    $headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n"; 
    $headers.= "Content-Transfer-Encoding: 7bit\r\n"; 

    $body = "This is a multi-part message in mime format.\n\n"; 
    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $text_content; 
    $body.= "\n\n"; 

    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/html; charset=\"UTF-8\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $html_content; 
    $body.= "\n\n"; 
    $body.= "--$mime_boundary--\n"; 

    $headers.= 'From: <[email protected]>' . "\r\n"; 
    $headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n"; 
    $headers.= 'Date: '.date('n/d/Y g:i A')."\r\n"; 
    $headers.= 'Reply-To: <[email protected]>' . "\r\n"; 

    return mail($to, $subject, $body, $headers); 

    } 

?> 

희망. 저희에게 알려주십시오.

관련 문제