2011-06-11 8 views
2

이메일을 보내기 위해 phpmailer 클래스를 사용합니다. 오류가 발생했습니다. "실행할 수 없습니다 :/smtp"코드가 아래 코드와 같습니다. 누군가가 내게 어떤 문제인지 제안 해 줄 수 있습니까?phpmailer 클래스 사용

require '../class.phpmailer.php'; 

try { 
    $mail = new PHPMailer(true); //New instance, with exceptions enabled 

    $body    = file_get_contents('contents.html'); 
    echo $body; 
    $body    = preg_replace('/\\\\/','', $body); //Strip backslashes 

    $mail->IsSMTP();       // tell the class to use SMTP 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Port  = 25;     // set the SMTP server port 
    $mail->Host  = "ssl://smtp.gmail.com"; // SMTP server 
    $mail->Username = "[email protected]";  // SMTP server username 
    $mail->Password = "1234567889";   // SMTP server password 

    $mail->IsSendmail(); // tell the class to use Sendmail 

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

    $mail->From  = "[email protected]"; 
    $mail->FromName = "First Last"; 

    $to = "[email protected]"; 

    $mail->AddAddress($to); 

    $mail->Subject = "First PHPMailer Message"; 

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

    $mail->MsgHTML($body); 

    $mail->IsHTML(true); // send as HTML 

    $mail->Send(); 
    echo 'Message has been sent.'; 
} catch (phpmailerException $e) { 
    echo $e->errorMessage(); 
} 
+0

정확히지고 어떤 오류 라인? –

답변

4

Gmail을 사용하면 설정이 잘못되었을 수 있습니다. 이 (수정 포트 및 SSL 주소) 시도 :, 또는

$mail->Port  = 465;     // set the SMTP server port 
$mail->Host  = "ssl://smtp.gmail.com"; // SMTP server 
$mail->Username = "[email protected]";  // SMTP server username 
$mail->Password = "1234567889"; 

를 사용하는 TLS :

$mail->Port  = 587;     // set the SMTP server port 
$mail->Host  = "tls://smtp.gmail.com"; // SMTP server 

편집 : 다음, 먼저 설정은 SMTP를 사용하여 제공 (아래이 줄을 제거 당신은 쓰루 센드 메일을 보내고 보낼 것을 말하고 configs에 잘못된 경로를 넣으십시오. 위의 설정 (또는 아래의 edit2)을 사용하여 하나의 서비스에만 고정하십시오 :

제거 :

$mail->IsSendmail(); // tell the class to use Sendmail 

가 Edit2가이 : 다른 옵션 (경우에 첫 번째 대답이 작동하지 않습니다) :

$mail->SMTPSecure = 'ssl'; 
$mail->Host = 'smtp.gmail.com'; 
+0

코드를 변경했지만 여전히 문제가 남아 있습니다. 실행할 수 없습니다 :/smtp – Deepa

+0

@Deepa 더 자세한 정보를 제공 한 다음 수신 한 오류 메시지를 명확히 설명해야합니다. if (! stristr (ini_get ('sendmail_path'), 'sendmail')) { $ this-> Sendmail = '/ var/qmail/bin/sendmail'에있는 –

+0

은 class.phpmailer.php에서 공용 함수 IsSendmail ; } $ this-> Mailer = 'sendmail'; } 방금 ​​센드 메일 경로를 '/ smtp'로 변경했습니다. – Deepa