Skip to main content
September 6, 2006
Question

email file attach

  • September 6, 2006
  • 4 replies
  • 746 views
I am trying to put together an email form that will allow visitors to a site to attach image files to the message and then send the whole thing to me. I know I can provide a link to their Outlook for this but I really want it all to happen from within the site.
Any help would be appreciated.
This topic has been closed for replies.

4 replies

September 14, 2006
Hi,

I tested it locally
September 14, 2006
Hi Forrest,
Could you tell me where I'm going wrong with this form.
All the php code appears at the top of the page above the form, I've tried saving the page as a .php page but that wouldn't preview in the browser. I'm sure this a perfectly simple thing to solve but I can't work it out.
September 7, 2006
i would leave the libmail code as is. it is worth taking some time to learn their object model. to send all of the messages to the same address (a good idea, that is the way it was set up...you dont want spammers using your server) remove the form input, and change this line of the code:

$m->To($_POST['recipient']);

to

$m->To('your email address here');


September 10, 2006
Hi I am looking for something like this except that instead of writing an email address as me@myplace.com I have a CV listing that I keep private by using a 'Contact Me' instead of the me@myplace.com link and then use a go to detail link to take to a contact form. So what I am asking is there a way to have the email sent to this person - me@myplace.com using the <?php echo $row_detailrs2['contactemail']; ?> or do I have to use $_POST? The recordset shows the data email through using $_GET['contactemail'], so to echo it will actually show the data for me.
I have everything working up until now.
Thanks hope you understand.
Theresa
September 10, 2006
you can use any method you want to set the recipient of the emails. i prefer to use post variables, as it is more secure. there is less chance of a spammer getting ahold of your form and spamming from your server. you could also get this address from the database or hard code a recipient in.
September 6, 2006
Hi,
I use this class to send html emails with attachments:

http://lwest.free.fr/doc/php/lib/index.php3?page=mail&lang=en


September 6, 2006
Thanks for the link. I don't know anything about php but I'll get the book out and see if I can make some sense of it.
September 6, 2006
try this form. download the libmail class, and put the file in the same directory that you have the form in.

<?php

if(isset($_POST['submit'])){
//upload the attached file

include "libmail.php";
$m= new Mail; // create the mail
$m->From($_POST['email']);
$m->To($_POST['recipient']);
$m->Subject($_POST['subject']);

$m->Body($_POST['message']); // set the body
//$m->Cc( "someone@somewhere.fr");
//$m->Bcc( "someoneelse@somewhere.fr");
$m->Priority(4) ; // set the priority to Low

if(is_uploaded_file($_FILES['file_attachment']['tmp_name'])){
move_uploaded_file($_FILES['file_attachment']['tmp_name'], basename($_FILES['file_attachment']['name']));
$m->Attach($_FILES['file_attachment']['name']) ; // attach a file
}

$m->Send(); // send the mail
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<form action="email.php" method="post" enctype="multipart/form-data" name="frm_mail" id="frm_mail">
<table width="550" border="0" cellspacing="1" cellpadding="2">
<tr>
<td colspan="2">
<?php if (isset($_POST['submit'])){
echo 'your message was successfully sent to '.
$_POST['recipient'].
' thanks!';
}
?>
</td>
</tr>
<tr>
<td colspan="2"><h1>Email recipient </h1></td>
</tr>
<tr>
<td width="150"><p>Send message to: </p></td>
<td><label>
<input type="text" name="recipient" />
</label></td>
</tr>
<tr>
<td colspan="2"><h1>Sender</h1></td>
</tr>
<tr>
<td><p>e-mail address: </p></td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td><p>subject:</p></td>
<td><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td colspan="2"><h1>Message</h1></td>
</tr>
<tr>
<td><p>Attachment</p></td>
<td>
<input name="file_attachment" type="file" id="this" size="31">
</td>
</tr>
<tr>
<td colspan="2"><textarea name="message" cols="57" rows="12" id="message"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Send Message"></td>
<td> </td>
</tr>
</table>
</form>

</body>
</html>

One thing,
I cut out a lot of things from this form, so if you have any problems let me know.