2013-07-29 137 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

相關問題