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
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", "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
Link to comment
Share on other sites

I guess what you need to do is something like this-

[code]<?php

if($photo)
$m->attachfile_raw($_SERVER['DOCUMENT_ROOT'].'/uploads'.$sFileName,$photo,$_FILES['photo']['type']);
else
$m->attachfile_raw("Path to default image here");

?>[/code]

Orio.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 mad

Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.