php - can't send attachment on phpMailer() -
i'm using phpmailer send email. when attached $body
email being send html body, attachment not being send. removed $body
, set text body ($email->body = 'abcd'
) , fine, attachment , body text send. can't use $email->body = $body;
, $email->addattachment("img/".$file_name);
@ same time.
this code:
<?php session_start(); $url = "http://{$_server['http_host']}"; $escaped_url = htmlspecialchars( $url, ent_quotes, 'utf-8' ); if(isset($_files['image'])){ $errors= array(); $file_name = $_files['image']['name']; $file_size =$_files['image']['size']; $file_tmp =$_files['image']['tmp_name']; $file_type=$_files['image']['type']; $tmp=explode('.',$_files['image']['name']); $file_ext=strtolower(end($tmp)); $expensions= array("jpeg","jpg","png"); if(in_array($file_ext,$expensions)=== false){ $errors[]="extension not allowed, please choose jpeg or png file."; } if($file_size > 2097152){ $errors[]='file size must excately 2 mb'; } if(empty($errors)==true){ move_uploaded_file($file_tmp,"img/".$file_name); }else{ print_r($errors); } } ?> <?php $body='<html><body>'; $body.='<img src="'.$escaped_url.'/img/img2.jpg" alt="" height="90" width="200" />' .$_post['date'].''; $body .='<table rules="all" style="border-color: #666;" cellpadding="10"> <tr style="background: #6699ff;">'; $body .='<td><strong>'.$_session["login_user_name"].'</strong> </td>'; $body .='<td>income (rs) : '.$_post['income'].'</td>'; $body .='<td>expences (rs) :'.$_post['expence'].'</td>'; $body .='<td>balance (rs) : '.$_post['balance'].'</td>'; $body .='</tr> <tr style="background: #eee;">'; $body .='<td><strong>category</strong> </td> <td><strong>item name</strong></td> <td><strong>amount</strong></td> <td><strong>image</strong></td> </tr> <tr >'; $body .='<td>'.$_post['cat'].' </td>'; $body .='<td>'.$_post['name'].'</td>'; $body .='<td>'.$_post['amount'].'</td>'; $body .='<td>'.$file_name.'</td>'; $body .='</tr> </table> </body> </html>'; ?> <?php require 'phpmailer/class.phpmailer.php'; $email = new phpmailer(); $email->from = $_session["login_email"]; $email->fromname = $_session["login_user_name"]; $email->subject = 'daily summery'; $email->body = $body; $email->ishtml(true); $email->addaddress( 'sample@gmail.com' ); $email->addattachment($escaped_url."/img/".$file_name); return $email->send(); ?>
file upload working fine, uploaded file , stored in img
folder correctly.
use real path url in src attribute.
<img src="http://example.com/img/img2.jpg" alt="" height="90" width="200" />
you must use this.
Comments
Post a Comment