View previous topic :: View next topic |
Author |
Message |
jhonenfreak Elder In Training

Joined: 28 Jan 2004 Posts: 3306 Location: Tallahassee
|
Posted: Sat May 09, 2009 4:22 pm Post subject: php email image attachment |
|
|
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 |
|
 |
cstdenis Evil Overlord

Joined: 31 Dec 1969 Posts: 6490 Location: In the tubes.
|
Posted: Sat May 09, 2009 4:40 pm Post subject: |
|
|
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 |
|
 |
jhonenfreak Elder In Training

Joined: 28 Jan 2004 Posts: 3306 Location: Tallahassee
|
Posted: Sun May 10, 2009 8:18 am Post subject: |
|
|
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 |
|
 |
Stratadrake Grammar nazi (and proud of it)

Joined: 05 May 2004 Posts: 13690 Location: Moo
|
Posted: Sun May 10, 2009 10:11 am Post subject: |
|
|
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 |
|
 |
jhonenfreak Elder In Training

Joined: 28 Jan 2004 Posts: 3306 Location: Tallahassee
|
Posted: Sun May 10, 2009 2:45 pm Post subject: |
|
|
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 |
|
 |
|