2013-04-15 3 views
0

함수에 아래 코드가 있습니다. 그러나 전자 메일에 첨부 파일을 추가하지 않습니다. 이메일은 정상적으로 전달되지만 첨부 파일은 없습니다.함수 내에서 phpmailer 코드가 작동하지 않습니다.

그러나 함수에서 코드를 제거하고 함수 파트가없는 별도의 파일을 추가하면 같은 디렉터리에서 제대로 작동합니다.

함수에 첨부 파일을 추가하지 않는 이유는 무엇입니까?

function resendOrder() 
{ 
    //global $siteEmailFrom, $siteEmailName, $dir; 
    require_once('OrderMailer/class.phpmailer.php');// need this to send email 

    $mail = new PHPMailer(); 
    // Now you only need to add the necessary stuff 

    // HTML body 

    $body = "Testing"; 

    // And the absolute required configurations for sending HTML with attachement 
    $mail->From  = "[email protected]******.co.uk"; 
    $mail->AddAddress("[email protected]******.co.uk", "My-webpage Website"); 
    $mail->Subject = "test for phpmailer-3"; 
    $mail->MsgHTML($body); 

    $mail->AddAttachment("ploxy.jpg"); 

    if(!$mail->Send()) { 
     echo "There was an error sending the message"; 
     exit; 
    } 
    else{ 
     echo "Message was sent successfully"; 
    } 
} 

답변

0

"ploxy.jpg"라는 첨부 파일의 이름을 참조 할 수 없습니다. 파일의 이름을 참조 할 수 없습니다. 기본적으로

$filePath = "../images/"; // Path to image, can be the empty string. 
$ploxy = $_FILES['ploxy']['tmp_name']; 
$mail->AddAttachment($filePath, $ploxy); 

:

임시 파일 이름을 참조해야합니다, 당신은 더 정확하게

$_FILES['ploxy']['tmp_name']; // temp_name can be anything 

광석과 같은 작업을 수행 할 수 있습니다 당신이 보내기 전에 당신은 스크립트 파일을 업로드해야합니다 그것; http://php.net/manual/en/features.file-upload.php

+0

감사합니다. 그럴 수 없습니다 : $ filePath = "../images/"; // 이미지의 경로는 빈 문자열이 될 수 있습니다. $ ploxy = $ _FILES [ 'ploxy.jpg'] [ 'tmp_name']; $ mail-> AddAttachment ($ filePath, $ ploxy); – user2183216

+0

아니요, 파일 확장자가 없어야합니다. – Jonast92

+0

도움이되고 문제가 해결되면 동의하십시오. 그것이 아니라면 나는 당신이 정확하게 그것을 구글로 여러 번 해결되었다고 말할 수 있습니다. – Jonast92

관련 문제