2014-06-09 2 views
0

그래서 나는 하루 이틀 동안 이것을 해왔습니다. 처음에는 코드 나이 터 SMTP 메일 클래스를 구축했는데 운이 없었습니다. 이 문제를 해결하기 위해 PHPMailer를 사용했습니다. 그리고 실망 스럽지만 여전히 행운은 없습니다.Codeigniter & PHPMailer

모든 세부 사항이 정확하다고 확신합니다. 나는 심지어 여러 개의 SMTP 서버를 시도했는데 그 중 일부는 gmail과 mandrill을 포함하고있다. 여기

내가 사용하고있는 코드입니다 (I이 다양한 수정 된 버전을 시도,하지만 난 당신에게 내가 현재 사용하고 하나의주지)

<?php 

class thankyou extends CI_Controller { 

function index() 
{ 

    $this->load->model('index'); 

    $header = array(
     'title' => 'Please Confirm', 
     'navigation' => $this->index->loadNavigation(), 
    ); 

    $this->load->view('header', $header); 

    $this->load->library('My_PHPMailer'); 

    $mail = new PHPMailer(); 
    $mail->IsSMTP();          // Set mailer to use SMTP 
    $mail->Host = 'smtp.mandrillapp.com';     // Specify main and backup server 
    $mail->Port = 587;         // Set the SMTP port 
    $mail->SMTPAuth = true;        // Enable SMTP authentication 
    $mail->Username = '[email protected]';    // SMTP username 
    $mail->Password = 'password4mandrill';     // SMTP password 
    $mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 
    $mail->SMTPDebug = 1; 

    $mail->From = '[email protected]ver.co.uk'; 
    $mail->FromName = 'Whatever'; 
    $mail->AddAddress('[email protected]', 'Josh Adams'); // Add a recipient    // Name is optional 

    $mail->IsHTML(false);         // Set email format to HTML 

    $mail->Subject = 'Here is the subject'; 
    $mail->Body = 'This is the HTML message body <strong>in bold!</strong>'; 
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

    if(!$mail->Send()) { 
     echo 'Message could not be sent.'; 
     echo 'Mailer Error: ' . $mail->ErrorInfo; 
     exit; 
    } 

} 

} 

?> 

필요하다면, 당신이 할 수있는을 난 그냥 CodeIgniter를하기 때문에 오류 2014-06-09 11:18:40 SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

+0

당신의 smtp 사용자 이름과 암호를 제거하십시오 – tomexsans

+0

그들은 진짜가 아닙니다 ... – Jarrod

+0

오케이 그래서 오류는 smtp 서버에 연결할 수 없다는 것입니다. 어쩌면 smtp 인증이 거짓이거나 설정 파일을 가지고 놀아 보려고합니다. – tomexsans

답변

0

을 얻을 Test it here

복잡성의 다른 방법을 사용하는 당신은 필요가 없습니다 이메일 도우미가 있습니다. 다음 구조를 사용하여 헬퍼를로드하고 메일을 보냅니다.

 $name="some name"; 
    $message="your text message"; 
    // set email data 
    $this->load->library('email'); 
    $this->email->set_mailtype("html"); 
    $this->email->from($this->input->post('sender_email'), $name); 
    $this->email->to('destination_email'); 
    $this->email->cc('alternative_email'); 
    $this->email->subject('Enquiry'); 
    $this->email->message($message); 
    $this->email->send(); 
+0

안녕하세요. 답장을 보내 주셔서 감사합니다. 이전 문장에서 언급 한 것처럼 이미 CodeIgniter 기본 메일 클래스를 사용해 보았지만 그 중 아무런 행운도 없었습니다. – Jarrod

2

이 함께보십시오 : 옵션의

$this->load->library('email'); 

$config['protocol'] = 'smtp'; 
$config['smtp_host'] = 'smtp.mandrillapp.com'; 
$config['smtp_user'] = '[email protected]'; 
$config['smtp_pass'] = 'password4mandrill'; 
$config['smtp_port'] = 587; 

$this->email->initialize($config); 

$this->email->from('[email protected]'); 
$this->email->to('[email protected]'); 
$this->email->subject('Test'); 
$this->email->message('Message'); 

if($this->email->send()) { 
    echo 'Sent'; 
} else { 
    $this->email->print_debugger(); 
} 

전체 목록 : http://ellislab.com/codeigniter/user-guide/libraries/email.html

0

당신이 겪고있는 문제는 스크립트보다 낮은 수준이다. SMTP 연결 실패는 서버와의 통신을 시작하지 못함을 의미하므로 인증 또는 메일 작성 방법과는 아무런 관련이 없습니다. 모든 메일은 mail()을 호출하거나 SMTP를 직접 말하면됩니다. 같은 문제, 당신이보고있어.

가장 일반적인 이유는 DNS가 작동하지 않는다는 것입니다. 다음으로 방화벽 문제를 살펴보고 fsockopenstream_socket_client 함수가 php env에서 비활성화되어 있지 않은지 확인하십시오.