2016-12-20 4 views
0
require_once('./PHPMailer-master/PHPMailerAutoload.php'); 
    $mail = new PHPMailer(); 
    $mail->isSMTP();          // Set mailer to use SMTP 
    $mail->Host = 'smtp.office365.com'; 
    $mail->ClearReplyTos(); 
    $mail->addReplyTo($organizer_email, $organizer);// Specify main and backup server 
    $mail->SetFrom('[email protected]', 'zyx'); 
    $mail->SMTPAuth = tls;        // Enable SMTP authentication 
    $mail->Username = '[email protected]';     // SMTP username 
    $mail->Password = 'xyzzzzz';    // SMTP password 
    $mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 
    $mail->Port = 587;         //Set the SMTP port number - 587 for authenticated TLS 
    $mail->addAddress($organizer_email); // Add a recipient 
    $content = file_get_contents($resume_attach_path); 
    $content = chunk_split(base64_encode($content)); 
    $eol = "\r\n"; 
    $tags = explode(',', $to); 
    foreach ($tags as $tag) { 
     $mail->addCC($tag); 
    } 
    $mail->WordWrap = 50;   
    $mail->Subject = $subject; 
    $mail->Body = $desc; 
    $mail->AltBody = $text; // in your case once more the $text string 
    $mail->Ical = $text; // ical format, in your case $text string 
    $mail->isHTML(true); // Set email format to HTML  
    //$mail->addStringAttachment($resume_attach_path,'base64'); 
    if ($mail->send()) { 
     return true; 
    }else{ 
     return false; 
    } 

난 그냥 iCal을 초대 볼 수없는 첨부 파일을 볼 수 있습니다,하지만 난 첨부 파일을 제거하면 내가 어떻게 보낼 수 있으며, iCal을 초대 볼 수 addAttachment를 사용하는 경우 phpmailer의 인라인 및 외부 문서 첨부.phpmailer

+0

헤더 및 콘텐츠 인코딩이 엉망이되는 이유는 무엇입니까? PHPMailer가 모든 것을 제공합니다. 'addAttachment'와'addEmbeddedAttachment'를 호출 할 수 있습니다. 보낸 사람 주소를 설정하지 않았습니다. 'clearReplyTos'를 호출 할 필요가 없습니다. 'msgHTML'을 호출하면'Body'와'AltBody'를 모두 덮어 씁니다. 그래서 미리 설정해 둘 필요가 없습니다. [documentation] (https://github.com/PHPMailer/PHPMailer/wiki)에 대한 기본적인 내용은 도움이 될 것입니다. – Synchro

+0

샘플 코드를 표시 할 수 있습니까 @ 싱크로 – dude

+1

PHPMailer와 함께 제공되는 샘플을보고 문서에 설명되어 있습니다. 아무런 차이가 없습니다. 단순히 임의의 함수를 호출하거나, 임의의 문자열을 설정하거나, 임의의 인코딩을 적용하지 말고, 수행중인 작업에 약간의 논리 만 적용하면됩니다. – Synchro

답변

0

나는 $attachment$_FILES['file']입니다이 코드에서 여기

<?php 
function sendMail($subject, $body, $name, $email, $attachment = null){ 
     $mail = new PHPMailer(true); 
     $mail->IsSMTP(); // telling the class to use SMTP 
     $mail->SMTPAuth = true; // enable SMTP authentication 
     $mail->SMTPSecure = "ssl"; // sets the prefix to the servier 
     $mail->Host = "**************"; // sets GMAIL as the SMTP server 
     $mail->Port = 465; // set the SMTP port for the GMAIL server 
     $mail->Username = "*************"; // GMAIL username 
     $mail->Password = "***********"; // GMAIL password 

     //Typical mail data 
     $mail->AddAddress($email, $name); 
     $mail->SetFrom('*********', '************'); 
     $mail->Subject = $subject;  
     $mail->Body = $body; 
     $mail->IsHTML(true); 
     if($attachment){    
      $mail->AddAttachment($attachment['tmp_name'], 
         $attachment['name']); 
     } 
     try{ 

      $mail->Send(); 

     } catch(Exception $e){ 
      //Something went bad 
      // print_r($e); 
      echo "Fail :("; 
      die; 
     } 
    } 
?> 

당신에게 간단한 작업 예를 도시하고있다. 이 함수를 호출하는 방법은 아래와 같습니다. 만 추가 간단한 ALT 또는 alt_inline 메시지 유형

에서 지원

:

sendMail($subject, $body, $name, $email, $_FILES['file']); 

는 PHPMailer 코드에서 언급을 참조 우편물에 Stackoverflow Question

+0

나는 이것을 시도했다 ... 이것은 인라인이 아닌 첨부 파일을 보여준다. u는 인라인과 첨부 파일을 모두 보여줄 수 없다. – dude

+0

ok 당신은 또한'$ mail-> addAttachment ('/calendar_file.ics'); 그리고 보이는 github 문제 -> https://github.com/PHPMailer/PHPMailer/issues/175 –

+0

Hussian 나는 그것을 시도했습니다 – dude

0

따라에서 Ical을 사용하려면 다른 첨부 파일, Ical 속성을 기반으로 Ical 파일을 추가하는 부분이 생략되었습니다.