phpmailer不发送附件

时间:2015-06-23 17:06:50

标签: phpmailer attachment email-attachments

有人知道为什么我的phpmailer不想发送附件吗?没有错误,我尝试了每个可能的文件位置,而且我仍然只接收纯文本邮件...

require '../phpmailer/PHPMailerAutoload.php';
            require '../phpmailer/class.phpmailer.php';

            $mail = new PHPMailer;

                                           // Enable verbose debug output

            $mail->isSMTP();                                      // Set mailer to use SMTP
              // Specify main and backup SMTP servers
            $mail->Host = 'serwerxxx.home.pl';  // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
                            // SMTP username
            $mail->Username = 'my@mail';                 // SMTP username                         // SMTP password
            $mail->Password = 'mypass';                           // SMTP password
            $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 465;                                    // TCP port to connect to

            $mail->From = 'my@mail.com';
            $mail->FromName = 'Mailer';
            // Add a recipient
            $mail->addAddress('mail@mail');               // Name is optional

                 // Add attachments
            $mail->AddAttachment("c20.jpg", "c20.jpg");    // Optional name                                // Set email format to HTML

            //$mail->AddAttachment("c20.jpg"); 
            //$mail->AddAttachment("../img/c20.jpg"); 
            //$mail->AddAttachment($_SERVER['../img/c20.jpg'])); 

            $mail->Subject = 'Here is the ółsubject'.$imie.' '.$nazwisko;
            $mail->Body    = 'das'.$format_wydruku1.'  '.$ile1.'This is the HTML messagóóęęe body <b>in SŁŁŚŚśśśłłóóbold!</b>';
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

            if(!$mail->send()) {
                echo 'Message could not be sent.';
                echo 'Mailer Error: ' . $mail->ErrorInfo;
            } else {
                echo 'Message has been sent';
            }

1 个答案:

答案 0 :(得分:2)

我花了一些时间来解决这个问题,对我来说这是一个路径问题 - 这为我解决了这个问题:

$mail->AddAttachment($_SERVER['DOCUMENT_ROOT']."/rest/of/your/path/to.pdf");