Logo
FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in
php email image attachment

 
Post new topic   Reply to topic    www.fanart-central.net Forum Index -> Computer Help
View previous topic :: View next topic  
Author Message
jhonenfreak
Elder In Training


Joined: 28 Jan 2004
Posts: 3306
Location: Tallahassee

PostPosted: Sat May 09, 2009 4:22 pm    Post subject: php email image attachment Reply with quote

Can I add an image upload to this form so that I can receive it as an email attachment?

register.html

Code:

<form method="post" action="register.php">

<?php

Name:
<br>
<input type="text" name="visitor" size="50">
<br><br>

Email:
<br>
<input type="text" name="visitormail" size="50">
<br><br>

Options:
<br>
<select name="options" style="size:1">
<option value="option 1">Option 1</option>
<option value="option 2">Option 2</option>
<option value="option 3">Option 3</option>
</select>
<br><br>

<input type="submit" value="Submit">
</form>



register.php

Code:

<?php

$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$options = $_POST['options];

if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail)) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a") ;

$option = $option ;
$subject = $option ;

$message = \n
$todayis [EST] \n
Option: $options \n
Artist: $visitor \n
Email: $visitormail \n
";

$from = "From: $visitormail\r\n";


mail("amy@starrust.com", $subject, $message, $from);

?>

_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
cstdenis
Evil Overlord


Joined: 31 Dec 1969
Posts: 6490
Location: In the tubes.

PostPosted: Sat May 09, 2009 4:40 pm    Post subject: Reply with quote

http://ca3.php.net/manual/en/features.file-upload.php

As for attaching the file to an email, that is much more complicated.

You can do the necessary mime manually. Add the extra headers, base64 encode the image, etc. But you are much better off using something like the Pear class Mail_Mime: http://pear.php.net/package/Mail_Mime
_________________
You will obey or molten silver will be poured into your ears.
Back to top
View user's profile Send private message Visit poster's website
jhonenfreak
Elder In Training


Joined: 28 Jan 2004
Posts: 3306
Location: Tallahassee

PostPosted: Sun May 10, 2009 8:18 am    Post subject: Reply with quote

I've never been able to understand PEAR before.

Can I have one submit button with two actions?

Code:

<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?> submit1a.php">
<p><input type="file" name="image_file" size="20"></p>
<p><input type="submit" value="Upload" name="action"></p>
</form>


Also, I've noticed that I can't upload a file without deleting the one in the folder first.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Stratadrake
Grammar nazi
(and proud of it)


Joined: 05 May 2004
Posts: 13682
Location: Moo

PostPosted: Sun May 10, 2009 10:11 am    Post subject: Reply with quote

jhonenfreak wrote:
Can I have one submit button with two actions?

Strictly speaking no, the 'action' element is tied to the form and not the submit button. However, you can use Javascript to change the form's 'action' element at run time, e.g:

Code:
<input type='submit' onclick='this.form.action="here.php" ' value='Submit Here />
<input type='submit' onclick='this.form.action="elsewhere.php" ' value='Submit elsewhere' />


You can also write a function to pick the action for you (based on whatever logic you need), e.g:

Code:
<script type='text/javascript'>
function pickAction(form)
{
  switch(something)
  {
    case foo:  form.action = 'target1.php';
    return;
    case bar:  form.action = 'target2.php';
    return;
    default:
    form.action = 'default.php';
  }
}
</script>

<input type='submit' onclick='pickAction(this.form)' value='Submit Where?' />


But beware, mixing Javascript and PHP is a very volatile thing and must be done carefully. It's safer to break out of a PHP block when you need to output Javascript, otherwise you should user HEREDOC strings for your code.
_________________
Strata here: Nanowrimo - FAC - dA - FA
Disclaimer: Posts may contain URLs. Click at your own risk.
Back to top
View user's profile Send private message
jhonenfreak
Elder In Training


Joined: 28 Jan 2004
Posts: 3306
Location: Tallahassee

PostPosted: Sun May 10, 2009 2:45 pm    Post subject: Reply with quote

Thanks for your help, guys. I found a script that uploads an image to my server and sends my email a link to it along with the user's name, email, etc.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    www.fanart-central.net Forum Index -> Computer Help All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum