| | |
Sending an image to email via PHP form?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 2
Reputation:
Solved Threads: 0
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.
And the next page:
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
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.
•
•
Join Date: Aug 2008
Posts: 29
Reputation:
Solved Threads: 1
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.
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.
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.
PHP Syntax (Toggle Plain Text)
<?php error_reporting(E_ALL); 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 <br><br> Regards, <br><br> Your Website/Name <br><br> <img src="cid:'.$id.'"> ','text/html'); $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.
![]() |
Similar Threads
- Email code check only showing on second page refresh! Can't figure this (PHP)
- Sending pic attachments via PHP form (PHP)
- Sending attachements over php (PHP)
Other Threads in the PHP Forum
- Previous Thread: Need Help To Complete Php Project!!
- Next Thread: PHP Dates
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken cakephp checkbox class cms code cookies cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert interactive ip javascript job joomla js limit link login mail mediawiki menu mlm mobile msqli_multi_query multiple mycodeisbad mysql navigation oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion regex remote script search server sessions sms source space sql stored subdomain syntax system table tutorial unicode update upload url validator variable video web webapplications websitecontactform xml youtube





