Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

email file attach

Guest
Sep 06, 2006 Sep 06, 2006
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.
TOPICS
Server side applications
756
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 06, 2006 Sep 06, 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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 06, 2006 Sep 06, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 06, 2006 Sep 06, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2006 Sep 07, 2006
Hi Forrest,

Thanks for the further help. Sorry to be a bit dense on this but could you answer the following:
Can I set the form up so that it automatically goes to one address (so the sender doesn't have to type in the email address that it goes to)?
Do I have to customize the libmail.php code?

Thanks again
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2006 Sep 07, 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');


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 09, 2006 Sep 09, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 10, 2006 Sep 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 11, 2006 Sep 11, 2006
Thanks for that Forrest, I think I can get it set up now.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 14, 2006 Sep 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.
Sorry about this
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2006 Sep 14, 2006
do you run .php page on server or localy ?

file:///c:/site/yourpage.php

or

http://localhost/site/yourpage.php
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 14, 2006 Sep 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 14, 2006 Sep 14, 2006
LATEST
Hi,

I tested it locally
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines