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