dc_jt Posted November 6, 2006 Share Posted November 6, 2006 HiI have a form where a user enters their name, address, postcode etc.I also have a field where a user can upload an image (This is optional)These details are then emailed to the intended recipient.If they choose not to upload an image I need to be able to still send an image. For example, a default image so that every user has an image attached to their email.Is this possible and if so how?Thanks Quote Link to comment Share on other sites More sharing options...
dc_jt Posted November 6, 2006 Author Share Posted November 6, 2006 Changed subject of this thread so it makes more senseAnyone got any ideas?Ive got this at the minute which sends the email:[quote]//send email $name=$_REQUEST['name']; $email=$_REQUEST['email']; $address=$_REQUEST['address1']; $town=$_REQUEST['town']; $city=$_REQUEST['city']; $postcode=$_REQUEST['postcode']; $country=$_REQUEST['country']; $license=$_REQUEST['license']; $memory=$_REQUEST['memory']; $photo=$sFileName; $datap=$_REQUEST['datap']; $subject = "Readers Archive"; $message = 'Name: ' .$name."\n". 'Email: '.$email."\n". 'Address: '.$address."\n". 'Town: '.$town."\n". 'City: '.$city."\n".'Postcode: '.$postcode."\n".'Country: '.$country."\n". 'Memory: '.$memory."\n". 'Photo: '.$photo; $m = new CMIMEMail("dconnor@******.com", "liverpool@test.com", $subject); $m->mailbody($message); if( $photo) { $m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']); }$m->send(); }}?> [/quote]Im guessing maybe an else statement after [quote]if( $photo) { $m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']); }[/quote]Anyone?Thanks Quote Link to comment Share on other sites More sharing options...
Orio Posted November 6, 2006 Share Posted November 6, 2006 I guess what you need to do is something like this-[code]<?phpif($photo) $m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']);else $m->attachfile_raw("Path to default image here");?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
dc_jt Posted November 6, 2006 Author Share Posted November 6, 2006 thats what i was thinking something like that but it doesnt work. The attachfile_raw function is:[quote]function attachfile_raw( $fname, $mailFileName, $content_type ) { if($f=@fopen($fname,"r")) { $this->atcmnt[$mailFileName]=fread($f,filesize($fname)); $this->atcmnt_type[$mailFileName]=$content_type; fclose($f);[/quote]Therefore, I need the file directory, the name of the image and the content type.I tried this[quote]$m->mailbody($message); if( $photo) { //die('Photo: '.$_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName); $m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']); //die(here); } else { $m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploadsImage.jpg',"uploadsImage.jpg",$_FILES['photo']['type']); } $m->send(); }}?> [/quote]Not too sure on the content type but this function works if there is an image selected so any idea??Thanks Quote Link to comment Share on other sites More sharing options...
dc_jt Posted November 6, 2006 Author Share Posted November 6, 2006 This is what I have now:[quote]$m = new CMIMEMail("dconnor@......", "liverpool@test.com", $subject); $m->mailbody($message); if( $photo != '') { $m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'.$sFileName,$photo,$_FILES['photo']['type']); } elseif( $photo == '') { $m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'."pixel.jpg","pixel.jpg",$_FILES['photo']['type']); } $m->send(); } }[/quote]The [quote]$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'.$sFileName,$photo,$_FILES['photo']['type']);[/quote]and the [quote]$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/'."pixel.jpg","pixel.jpg",$_FILES['photo']['type']);[/quote]both work because I have tested them both.So it must be something to do with the if else statements maybe??The first bit works fine, if a photo is selected attach it, but when there is no photo then the pixel.jpg is not attached. (This line definitely works though because i swapped it with the one above and it attached the pixel.jpg when a photo was selected.Please this is driving me madThanks Quote Link to comment Share on other sites More sharing options...
dc_jt Posted November 6, 2006 Author Share Posted November 6, 2006 Sorted it now :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.