2013-07-29 3 views
-3

메일을 보내려면 phpmailler를 사용하고 메일은 첨부 파일없이 성공적으로 작동합니다. 첨부 파일이있는 메일을 보내려고합니다. 이 코드를 시도했습니다.phpmailer를 사용하여 첨부 파일이있는 이메일을 보내려합니다.

미리 감사드립니다.

$s2="select * from tbl_new_user where login_name='".$rw['clientname']."'"; 
$q2=mysql_query($s2) or die($s2); 
$row=mysql_fetch_array($q2); 

$s22="select * from tbl_job_schedule where clientname='".$rw['clientname']."' and jobdate='".$_SESSION['strmonth']."-".$_REQUEST['dt']."-".$_SESSION['yy']."'"; 
$q22=mysql_query($s22) or die($s22); 
$row2=mysql_fetch_array($q22); 

$mail = new PHPMailer; 

$mail->IsSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtpout.secureserver.net'; // Specify main and backup server 
$mail->Port = '80'; 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = 'username';       // SMTP username 
$mail->Password = 'password';       // SMTP password 
$mail->SMTPSecure = '';       // Enable encryption, 'ssl' also accepted 
$mail->SMTPDebug = 1; 

$mail->From = '[email protected]'; 
$mail->FromName = '[email protected]'; 
$mail->AddAddress($row['client_email'], ''); // Add a recipient 
$mail->AddAddress($row['client_email2']);  // Name is optional 
$mail->AddAddress($row['client_email3']); 
$mail->AddAddress($row['client_email4']); 
$mail->AddAddress($row['client_email5']); 
$mail->AddAddress($row['client_email6']); 
$mail->AddReplyTo('[email protected]', 'Information'); 
//$mail->AddCC('[email protected]'); 
//$mail->AddBCC('[email protected]'); 

$mail->WordWrap = 50;  
          // Set word wrap to 50 characters 
if($row2['file1']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file1'].'');   // Add attachments 
} 

if($row2['file2']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file2'].'');   // Add attachments 
} 

if($row2['file3']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file3'].'');   // Add attachments 
} 

if($row2['file4']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file4'].'');   // Add attachments 
} 

if($row2['file5']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file5'].'');   // Add attachments 
} 

if($row2['file6']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file6'].'');   // Add attachments 
} 

if($row2['file7']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file7'].'');   // Add attachments 
} 

if($row2['file8']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file8'].'');   // Add attachments 
} 

if($row2['file9']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file9'].'');   // Add attachments 
} 
if($row2['file10']!='') 
{       
$mail->AddAttachment('kurtacompany/techreporting/upload/'.$row2['file10'].'');   // Add attachments 
} 



//$mail->AddAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->IsHTML(true);         // Set email format to HTML 

$mail->Subject = 'Reporting'; 
$mail->Body = '<p>This is an automated email report for the work done today. 

Below are the comments showing on what we have worked,if you have any questions please go to the reporting URL provided and update your comment or can send a separate email to me directly on my email ID provided.</p> 


<b>Work Comments : "'.$row2['client_cmnt'].'"</b>'; 
$mail->AltBody = ''; 

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

echo 'Message has been sent'; 

      echo "<script>window.close()</script>"; 

} 
+0

당신이 오류를 얻고있다. 그리고 너무 많은 파일을 첨부하고 있습니다. –

+0

그 코드에 어떤 문제가 있습니까? – JJJ

+0

코드가 유효 해 보입니다. 아마도 $ row2에 값이 없거나 kurtacompany/techreporting/upload/'.$ row2 [ 'file1']이 유효한 경로를 생성하지 않습니다 ($ row2 등의 내용을 디버깅 해보십시오). – RMK

답변

-1

첨부 파일에 사용중인 경로가 올바른지 확인하십시오.

즉 파일이 kurtacompany/techreporting/upload/'.$row2['file3']에 있습니까?

처음부터 /이 누락되어있는 것처럼 간단하여 루트 디렉토리에서 검색을 시작해야 함을 나타낼 수 있습니다. 의심스러운 경우 확인하기 위해 절대 링크를 시도하십시오

http://www.mywebsite.com/kurtacompany/techreporting/upload/'.$row2['file3']

+0

$ mail-> AddAttachment ('http://www.kurtacompany.com/techreporting/upload/'.$row2 ['file1 '].' ') ; 이 경로를 시도했지만 여전히 내 메일에서 첨부 파일을 찾을 수 없습니다. –

+0

링크에'kurtacompany.com' 앞에'http : // '를 포함시켜야합니다. 그대로, phpmailer 처리 스크립트가 들어있는 폴더 안에 'kurtacompany.com'이라는 폴더가 있습니다. '$ mail-> AddAttachment ('http://kurtacompany.com/techreporting/upload/...);' – Alfie

+0

링크를 기반으로 다음과 같은 상대 링크가 작동 할 것으로 기대합니다. '/'는 루트 디렉토리를 상징하는 시작 부분에있다.)'$ mail-> AddAttachment ('/ techreporting/upload/...); – Alfie

관련 문제