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>

And the next page:

$status = "OK";

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

/////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 = "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 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:


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!



Recommended Answers

All 4 Replies

Anyone? Really need this done..


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.

define('DISPLAY_XPM4_ERRORS', true);
require_once 'includes/mailer/MIME.php';

$id = MIME::unique();
$text = MIME::message('Text version of message.', 'text/plain');
$html = MIME::message('
Your mail message here
Your Website/Name
<img src="cid:'.$id.'">
$file = 'includes/yourlogoname.jpg';
$at[] = MIME::message(file_get_contents($file), FUNC::mime_type($file), 'yourlogoname_notthepath.jpg', null, 'base64', 'inline', $id);
$mess = MIME::compose($text, $html, $at);
$send = mail('toaddress@here.com', 'Then type your subject here', $mess['content'], 'From: you@yourmail.com'."\n".$mess['header']);

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.

So did you get it to work?

can you please help me with this code. i am trying to embed a image in my mail and its showing as string of alphanumeric ..

function send_mail_pear()
		$crlf = "\n";
		$to = "mail@mail.in";
		$head = ("From: mail@mail.in". "\r\n");
		$head .= "Content-type: text/html\r\n";
		$head .= "Content-Type: image/jpeg"; 
		$mime = new Mail_mime($crlf);
		echo $head. "<br/>";
		$mime->setHTMLBody('<html><body><img src="map_6.gif"> <p>You see this image.</p></body></html>');
		$mime->addHTMLImage('map_6.gif', 'image/gif');	
		$subject = "Test mail";
		$mailBody = $mime->get();
		$mail =& Mail::factory('mail');
		echo $mailBody ;
		/*if(mail($to, $subject, $mailBody, $head)){
			echo "successful";
		} else {
			echo "Mail Not sent";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.