Php 电子邮件附件在Laravel 5中不起作用
我正在尝试用电子邮件发送Laravel 5中的附件。我使用的是Ubuntu 14.04 LTS操作系统 邮件功能工作正常,没有附件 这是我用来发送电子邮件的代码Php 电子邮件附件在Laravel 5中不起作用,php,laravel,Php,Laravel,我正在尝试用电子邮件发送Laravel 5中的附件。我使用的是Ubuntu 14.04 LTS操作系统 邮件功能工作正常,没有附件 这是我用来发送电子邮件的代码 \Swift_Preferences::getInstance()->setCacheType('disk')->setTempDir('/tmp'); \Mail::queue('emails.campaignemailtesttemplate', array($email_data),function($message)
\Swift_Preferences::getInstance()->setCacheType('disk')->setTempDir('/tmp');
\Mail::queue('emails.campaignemailtesttemplate', array($email_data),function($message) use ($email_array) {
try{
$filepath = 'http://localhost:8000/attachment/AcFFXx2pXq.png';
$message->attach($filepath);
$message->to($email_array['email_id'])->subject($email_array['email_subject']);
}
catch (Exception $e)
{
}
});
这就是错误:
ErrorException in FileByteStream.php line 142: fopen(http://localhost:8000/attachment/AcFFXx2pXq.png): failed to open stream: HTTP request failed!
allow_url_fopen在php.ini上
文件扩展名可以是doc、docx、pdf、xcel之类的任何东西。文件路径来自数据库
任何帮助都将不胜感激
提前感谢。试试这个(内联)
注意:确保路径正确
试试这个
$data = array("html"=>$msg);
$result = Mail::send('email',$data,function($message) use($to,$from) {
$file = 'http://'.$_SERVER["HTTP_HOST"].'/upload/startup-1.png';
$message->attach($file);
$message->to($to);
$message->from($from);
} );
将文件附加到邮件时,还可以指定MIME类型和/或显示名称:
$pathToFile = 'http://localhost:8000/attachment/AcFFXx2pXq.png';
$mime = 'image/png';
$display = 'campaign';
$message->attach($pathToFile, ['as' => $display, 'mime' => $mime]);
查看更多详细信息:谢谢大家的回复 我已经解决了这个问题 apache2、php5和包含代码的文件夹存在权限问题 我已将www数据组分配到/var/www/html中的项目文件夹,并在www数据组中添加了我(root用户),并授予该组777权限
这对我有用。希望使用Ubuntu操作系统的人能找到有用的答案:)出于一些疯狂的原因,我为此奋斗了一整天。我在共享主机上托管了laravel,所以我有一个cpanel文件管理器 特别是如果你试图上传的图像是在你的公共目录中,就像我的情况一样。确保您的公用文件夹或www文件夹至少具有755权限 使用asset('images/whatever.jpg')是行不通的,因为它提供了一个绝对路径,如 使用此工具:
$message->embed(public_path().'/images/logo.png')
注意:public path返回/home/dirname/public,但是如果您使用的是像我一样的共享主机和cpanel,那么公共文件夹称为public_html,所以我在下面使用它,这对我很有用
$message->embed(public_path().'_html/images/logo.png')
按照您的建议更改代码后,我遇到了相同的错误。请阅读可能会有所帮助
$message->embed(public_path().'/images/logo.png')
$message->embed(public_path().'_html/images/logo.png')