使用PHPmailer发送附件

弗朗西斯卡

我正在使用PHPmailer库发送电子邮件,并且需要发送附件。

目前,该文件存储在服务器上,我具有指向var中存储的文件的链接$link

我正在使用以下内容尝试添加附件,但是电子邮件中没有附件:

$phpmailer->AddAttachment('$link');

我也尝试过使用硬编码路径而不是变量进行尝试:

$phpmailer->AddAttachment('http://mysite.co.uk/link/to/my/file.pdf');

电子邮件出现了,但是没有任何附件。

我曾尝试使用phpmailerException任何错误,但没有得到回应。

我还能如何使用PHPmailer发送附件?

完整的PHP代码:

require_once 'library/PHPMailer.php';
        $phpmailer = new PHPMailer();
        $phpmailer->isSMTP(); //switch to smtp
        $phpmailer->Host = 'smtp.sendgrid.net';
        $phpmailer->SMTPAuth = true;
        $phpmailer->SMTPSecure = 'ssl';
        $phpmailer->Port = 465;
        $phpmailer->Username = 'username';
        $phpmailer->Password = 'password';
        $phpmailer->AddAttachment('http://mysite.co.uk/blah/cv.pdf');
        //$phpmailer->AddAttachment('$link');

        $subject = 'Job Application';

        $messageConfirmation = "The <b> 'Apply for Job' </b> form has recently been completed on <b>www.mysite.com.</b><br/><br/> <b>Please see contact details below:<br /><br/> </b>";
        $messageConfirmation.= "<b>Applying for:</b> $title <br/><br/>";
        $messageConfirmation .= "<b>Name:</b> $name <br/><br/><b>Surname:</b> $surname <br/><br/> <b>Email:</b> $email <br/><br/> <b>Comment:</b> $comment <br/><br/>";
        $messageConfirmation .= "<b>CV:</b> $link<br /><br />";
        $messageConfirmation .= "Please can you call them back in the next 24 hours. <br/><br/> Thank you \n\nMy Site<br/><br/>";


        $imgheader = 'http://blah.co.uk/blah/wp-content/uploads/2014/11/header.png';
        $imgfooter = 'http://blah.co.uk/blah/wp-content/uploads/2014/11/footer.png';

        $message = '<!DOCTYPE HTML>'.
            '<head>'.
            '<meta http-equiv="content-type" content="text/html">'.
            '<title>Email notification</title>'.
            '</head>'.
            '<body>'.
            '<div id="header" style="width: 600px;height: auto;margin: 0 auto;color: #fff;text-align: center;font-family: Open Sans,Arial,sans-serif;">'.
            '<img src="'.$imgheader.'" >'.
            '</div>'.

            '<div id="outer" style="width: 600px;margin: 0 auto;margin-top: 10px;">'.
            '<div id="inner" style="width: 600px;margin: 0 auto; padding-left: 20px;background-color: #fff;font-family: Open Sans,Arial,sans-serif;font-size: 13px;font-weight: normal;color: #444;margin-top: 10px;">'.
            '<p>'.$messageConfirmation .'</p>'.

            '</div>'.
            '</div>'.

            '<div id="footer" style="width: 600px;height: auto;margin: 0 auto;text-align: center;padding: 10px;font-family: Verdena;">'.
            '<img src="'.$imgfooter.'" >'.
            '</div>'.
            '</body>';


        $phpmailer->IsHTML(true);
        $phpmailer->AddAddress(CONTACTUSFORMEMAIL);
        $phpmailer->From = CONTACTUSFORMEMAIL;
        $phpmailer->FromName ='blah';
        $phpmailer->WordWrap   = 50; // set word wrap to 50 characters
        $phpmailer->Subject    = $subject;
        $phpmailer->Body       = $message;
        $phpmailer->Send();



        $data['success'] = true;
        $data['message'] = 'Thank you for your application';
格林基

问题在于,函数AddAttachment使用函数is_file(),并且在访问URL时文件返回false(这也适用于相对URL),is_file()仅接受文件路径。因此,通常phpmailer应该向错误容器添加错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法使用PHPmailer发送附件

来自分类Dev

使用PHPmailer发送附件-返回.dat文件

来自分类Dev

使用phpmailer从表单发送附件不起作用

来自分类Dev

使用phpmailer和html表单发送带有附件的邮件

来自分类Dev

使用 PHPMailer 发送电子邮件附件

来自分类Dev

PHPMailer发送邮件,但不附带文件附件

来自分类Dev

PHPMailer-不带正文发送附件

来自分类Dev

PHPMailer发送邮件,但不附带文件附件

来自分类Dev

PHPmailer多个附件仅首先发送

来自分类Dev

使用phpmailer类在电子邮件中发送附件:无法访问文件

来自分类Dev

使用phpmailer发送带有动态附件(pdf)的邮件会返回pdf错误

来自分类Dev

使用PHPMailer根据用户已选中的复选框将附件发送给用户?

来自分类Dev

使用PHPMailer从目录发送的电子邮件附件并非总是最新的

来自分类Dev

使用phpmailer类在电子邮件中发送附件:无法访问文件

来自分类Dev

使用phpmailer发送带有动态附件(pdf)的邮件会在pdf中返回错误

来自分类Dev

使用 phpmailer 发送两个不同的带有附件的电子邮件

来自分类Dev

使用reqwest发送附件

来自分类Dev

使用PHPMailer进行文件附件验证

来自分类Dev

PHPMailer-发送附件,但不重置表格

来自分类Dev

2019如何使用PHPMailer V6.0.7和PHP从一个Web表单发送多个附件

来自分类Dev

PHP使用PHPMailer发送邮件

来自分类Dev

使用python使用Mailgun发送附件

来自分类Dev

使用PHPMailer在电子邮件中加密的附件

来自分类Dev

无法使用PHPMailer在邮件中添加附件

来自分类Dev

PHPMailer文件附件

来自分类Dev

PHPMailer的文件附件

来自分类Dev

TCPDF:PHPMailer的附件是空的

来自分类Dev

PHPMailer添加附件

来自分类Dev

PHPMailer文件附件

Related 相关文章

热门标签

归档