Jump to content

Default email attachment


dc_jt

Recommended Posts

Hi

I 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
Link to comment
https://forums.phpfreaks.com/topic/26295-default-email-attachment/
Share on other sites

Changed subject of this thread so it makes more sense

Anyone 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", "[email protected]", $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
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
This is what I have now:

[quote]$m = new CMIMEMail("dconnor@......", "[email protected]", $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 mad

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.