我想使用phpmailer发送带有附件的电子邮件 [英] i want to send email with attachments using phpmailer

查看:65
本文介绍了我想使用phpmailer发送带有附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phpmailler发送邮件,邮件可以成功运行,但没有附件.我想发送带有附件的邮件. 我已经尝试过此代码.

i am using phpmailler for sending mail,mail works successfully but without attachments. i want to send mail with attachments. i have tried this code.

提前谢谢.

$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 = 'abc@abc.com';
$mail->FromName = 'abc@abc.com';
$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('info@example.com', 'Information');
//$mail->AddCC('cc@example.com');
//$mail->AddBCC('bcc@example.com');

$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>";

}

推荐答案

确保用于附件的路径有效.

Make sure the path your are using for your attachments is valid.

kurtacompany/techreporting/upload/'.$row2['file3']是否存在文件?

可能很简单,因为您从一开始就缺少/,表明它应该从根目录开始搜索.如有疑问,请尝试使用绝对链接进行确认:

It might be as simple as you missing a / from the beginning to indicate it should start searching from the root directory. If in doubt, try an absolute link to confirm:

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

这篇关于我想使用phpmailer发送带有附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆