Sending an image to email via PHP form?

Reply

Join Date: Aug 2008
Posts: 2
Reputation: Egnited is an unknown quantity at this point 
Solved Threads: 0
Egnited Egnited is offline Offline
Newbie Poster

Sending an image to email via PHP form?

 
0
  #1
Aug 15th, 2008
I am developing a [mobile] website that needs to allow visitors to send both an image (which is on my server) and a custom message to a friend's email using a PHP form. I have to keep it mobile-compatible, so I can't use java, etc.

Here is my form so far... but the form can be totally scratched if necessary. I'm not very knowledgeable at PHP.

<form method=post action=tellck.php>
      <table  border="0" cellpadding="0" cellspacing="0" align=center>
<tr bgcolor='#f1f1f1'><td colspan=2 align=center><font face='Verdana' size='2' ><b>Send Image to Friend</b></font></td></tr>

<tr><td width=100><font face='Verdana' size='2' >Your Name</font></td><td width=200><input type=text name=y_name></td></tr>
<tr bgcolor='#f1f1f1'><td><font face='Verdana' size='2' >Your Email</font></td><td><input type=text name=y_email></td></tr>
<tr ><td><font face='Verdana' size='2' >Your Friend's Name</font></td><td><input type=text name=f_name></td></tr>
<tr bgcolor='#f1f1f1'><td><font face='Verdana' size='2' >Friend's Email</font></td><td><input type=text name=f_email></td></tr>
<tr ><td><font face='Verdana' size='2' >Your Message</font></td><td><textarea name=y_msg rows=5 cols=20></textarea></td></tr>

<tr bgcolor='#f1f1f1'><td colspan=2 align=center><font face='Verdana' size='2' ><input type=submit value='Send'></font></td></tr>
</table>
</form>

And the next page:

<?
$status = "OK";
$msg="";
$y_email=$_POST['y_email'];
$y_name=$_POST['y_name'];
$f_email=$_POST['f_email'];
$f_name=$_POST['f_name'];
$y_msg=$_POST['y_msg'];


if(substr_count($y_email,"@") > 1  or substr_count($f_email,"@") > 1){
$msg .="Use only one email address<BR>"; 
$status= "NOTOK";
}
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $y_email)){ // checking your email 
$msg .="Your email address is not correct<BR>"; 
$status= "NOTOK";}

if (strlen($y_name) <2 ) { // checking your name
$msg .="Please enter your name<BR>"; 
$status= "NOTOK";}

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $f_email)) { // checking friends email 
$msg .="Your Friends address is not correct<BR>"; 
$status= "NOTOK";}

if (strlen($f_name) <2 ) { // checking freinds name
$msg .="Please enter your friend's name<BR>"; 
$status= "NOTOK";}

if (strlen($y_msg) <2 ) { // checking Message details
$msg .="Please enter your message details<BR>"; 
$status= "NOTOK";}

if($status=="OK"){ // all validation passed
/////////// Sending the message starts here //////////////
$ip=$_SERVER['REMOTE_ADDR']; // Collect the IP address of visitor

$ref=@$HTTP_REFERER; 
/////Message at the top of the page showing the url////
$header_message = "Hey $f_name!  Your friend $y_name thought you'd enjoy this picture!";
/// Body message prepared with the message entered by the user ////
$body_message =$header_message."\n".$y_msg."\n";
$body_message .="\n This message was sent to you using http://www.website.mobi";

//// Mail posting part starts here /////////

$headers="";
//$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers; 
 // Un comment the above line to send mail in html format
$headers4=$y_email;         // Change this to change from address
$headers.="Reply-to: $headers4\n";
$headers .= "From: $headers4\n"; 
$headers .= "Errors-to: $headers4\n"; 

$subject="Request to visit URL";

mail($f_email,$subject,$body_message,$headers);



////// Mail posting ends here ///////////
echo "<center><font face='Verdana' size='2' color=green>Thank You, Your message posted to $f_name</font></center>";

//////////// Sending the message ends here /////////////
}else{// display the error message
echo "<center><font face='Verdana' size='2' color=red>$msg</font></center>";
}
?>


This produces:

http://www.egnited.net/demo/tell.php


So, how can I make the form send an image (from a URL) to the email?

I also need the have the form send to the user from MY email, not the user's...


I would really appreciate any help on this!

Thanks!

Tom
Last edited by Egnited; Aug 15th, 2008 at 1:58 am.
Attached Files
File Type: php tell.php (1.1 KB, 5 views)
File Type: php tellck.php (2.7 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 2
Reputation: Egnited is an unknown quantity at this point 
Solved Threads: 0
Egnited Egnited is offline Offline
Newbie Poster

Re: Sending an image to email via PHP form?

 
0
  #2
Aug 15th, 2008
Anyone? Really need this done..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 29
Reputation: derekcpt is an unknown quantity at this point 
Solved Threads: 1
derekcpt derekcpt is offline Offline
Light Poster

Re: Sending an image to email via PHP form?

 
0
  #3
Aug 15th, 2008
Hi.

I'm using xpertmailer. At first, I had to figure out how to use it, but it is really fantastic. When including an inmage in your mail, it obviously means that the mail needs to be html. With xpertmail, you can have embedded images and attachments as well.

Go to http://xpertmailer.sourceforge.net/

The page below is my email page. Hope this helps. Since I have searched the net for ages to find the perfect script.

  1. <?php
  2. error_reporting(E_ALL);
  3. define('DISPLAY_XPM4_ERRORS', true);
  4. require_once 'includes/mailer/MIME.php';
  5.  
  6. $id = MIME::unique();
  7. $text = MIME::message('Text version of message.', 'text/plain');
  8. $html = MIME::message('
  9. Your mail message here
  10. <br><br>
  11. Regards,
  12. <br><br>
  13. Your Website/Name
  14. <br><br>
  15. <img src="cid:'.$id.'">
  16. ','text/html');
  17. $file = 'includes/yourlogoname.jpg';
  18. $at[] = MIME::message(file_get_contents($file), FUNC::mime_type($file), 'yourlogoname_notthepath.jpg', null, 'base64', 'inline', $id);
  19. $mess = MIME::compose($text, $html, $at);
  20. $send = mail('toaddress@here.com', 'Then type your subject here', $mess['content'], 'From: you@yourmail.com'."\n".$mess['header']);
  21. ?>

If you don;t get it to work, let me know.

I don;t want to include my web address, but I'll do. To see an example, go to crimerescue.com and register for free, you will get a signup amil. Or I think you can just use the recommendation page.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 29
Reputation: derekcpt is an unknown quantity at this point 
Solved Threads: 1
derekcpt derekcpt is offline Offline
Light Poster

Re: Sending an image to email via PHP form?

 
0
  #4
Aug 18th, 2008
So did you get it to work?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC