i have this form and would like an extra field to allow a jpeg file to be attached and i havnt a clue any help please cheers Doug <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table width="600" border="0" cellspacing="0" cellpadding="2" align="center"> <tr> <td align="left"><span>Name:</span></td> <td align="left"><input type="text" name="Name"></td> </tr> <tr> <td align="left"><span>Telephone Number:</span></td> <td align="left"><input type="text" name="TelNo"></td> </tr> <tr> <td align="left"><span>Email:</span></td> <td align="left"><input type="text" name="Email"></td> </tr> <tr> <td align="left" valign="top"><span>Message:</span></td> <td align="left"><textarea name="MsgBody" cols="40" rows="5"></textarea></td> </tr> <tr> <td align="left"><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> <?php } else { error_reporting(0); $recipient = 'caravan.exchange@googlemail.com'; $subject = 'Caravan Holiday Exchange'; $from = stripslashes($_POST['Name']); $telno = stripslashes($_POST['TelNo']); $email = stripslashes($_POST['Email']); $company = stripslashes($_POST['Company']); $message = stripslashes($_POST['MsgBody']); $msg = "Message from: $from\n\nTelephone Number: $telno\n\nEmail: $email\n\nUsers Message:\n\n $message\n\n"; if (mail($recipient, $subject, $msg)) echo nl2br("<b>Message Sent</b>"); else echo "An unknown error occurred."; } ?> </tr> </table> </form> <p> </p> <p> </p> </body> PHP:
Hi Doug, The best thing you can do is search! Try this in Google "php file upload" for instant help. Good luck
<?php define("EMAIL_TO", 'krakjoe@krakjoe.info'); define("EMAIL_SUBJECT", 'New POC from %s' ); define("EMAIL_FROM", 'krakjoe@krakjoe.info' ); define("EMAIL_MAX_ATTACHMENT_SIZE", '300000' ); function Attach( $message, $headers = null, $params = null ) { // Build your message from your posted form $message = nl2br( sprintf( "Name : %s\n". "Telephone : %s\n". "Email : %s\n". "%s", $_POST['Name'], $_POST['TelNo'], $_POST['Email'], $message ) ); // start to add to headers $headers .= sprintf( "From: %s\n", EMAIL_FROM ); // check to see if we are attaching if( is_uploaded_file( $_FILES['attach']['tmp_name'] ) ) { // the content needs a boundary so that email clients know where to get data $boundary = sprintf( '==Multipart_Boundary_x%s', md5( time( ) ) ) ; // continue to build headers, adding the boundary for attached data $headers .= sprintf( "MIME-Version: 1.0\n". "Content-Type: multipart/mixed;\n boundary=\"%s\"\n", $boundary ); // edit message to include data and boundaries $message = sprintf( "This is a multi-part message in MIME format.\n\n". "--%s\n". "Content-Type: text/html; charset=\"iso-8859-1\"\n". "Content-Transfer-Encoding: 7bit\n\n". "%s\n\n". "--%s\n". "Content-Type: %s;\n name=\"%s\"\n". "Content-Disposition: attachment;\n filename=\"%s\"\n". "Content-Transfer-Encoding: base64\n\n". "%s\n\n". "--%s-\n", $boundary, $message, $boundary, $_FILES['attach']['type'], $_FILES['attach']['name'], $_FILES['attach']['name'], chunk_split( base64_encode( file_get_contents( $_FILES['attach']['tmp_name'] ) ) ), $boundary ); } // send the original message with the file attached return mail( EMAIL_TO, sprintf( EMAIL_SUBJECT, $_SERVER['REMOTE_ADDR'] ), $message, $headers, $params ); } if( $_POST ) { if( Attach( $_POST['message'] ) ) { printf( "<center><font color=blue>Your message was sent to %s</font></center>", EMAIL_TO ); } else { print("<center><font color=red>Failed to deliver your message</font></center>"); } } ?> <html> <head> <title></title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="<?=EMAIL_MAX_ATTACHMENT_SIZE ?>" /> <table width="600" border="0" cellspacing="0" cellpadding="2" align="center"> <tr> <td align="left"><span>Name:</span></td> <td align="left"><input type="text" name="Name"></td> </tr> <tr> <td align="left"><span>Telephone Number:</span></td> <td align="left"><input type="text" name="TelNo"></td> </tr> <tr> <td align="left"><span>Email:</span></td> <td align="left"><input type="text" name="Email"></td> </tr> <tr> <td align="left" valign="top"><span>Message:</span></td> <td align="left"><textarea name="MsgBody" cols="40" rows="5"></textarea></td> </tr> <tr> <td align="left" valign="top">Attach Image :</td> <td><input type="file" name="attach" /></td> </tr> <tr> <td align="left"><input type="submit" value="Send"></td> </tr> </table> </form> </body> </html> PHP:
getting this error Warning: mail() [function.mail]: SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE. in /misc/34/000/087/930/6/user/web/caravan-holiday-exchange.com/contact.php on line 122 Failed to deliver your message cheers Doug
<?php define("EMAIL_TO", 'krakjoe@krakjoe.info'); define("EMAIL_SUBJECT", 'New POC from %s' ); define("EMAIL_FROM", 'krakjoe@krakjoe.info' ); define("EMAIL_MAX_ATTACHMENT_SIZE", '300000' ); function Attach( $message, $headers = null ) { // Build your message from your posted form $message = nl2br( sprintf( "Name : %s\n". "Telephone : %s\n". "Email : %s\n". "%s", $_POST['Name'], $_POST['TelNo'], $_POST['Email'], $message ) ); // start to add to headers $headers .= sprintf( "From: %s\n", EMAIL_FROM ); // check to see if we are attaching if( is_uploaded_file( $_FILES['attach']['tmp_name'] ) ) { // the content needs a boundary so that email clients know where to get data $boundary = sprintf( '==Multipart_Boundary_x%s', md5( time( ) ) ) ; // continue to build headers, adding the boundary for attached data $headers .= sprintf( "MIME-Version: 1.0\n". "Content-Type: multipart/mixed;\n boundary=\"%s\"\n", $boundary ); // edit message to include data and boundaries $message = sprintf( "This is a multi-part message in MIME format.\n\n". "--%s\n". "Content-Type: text/html; charset=\"iso-8859-1\"\n". "Content-Transfer-Encoding: 7bit\n\n". "%s\n\n". "--%s\n". "Content-Type: %s;\n name=\"%s\"\n". "Content-Disposition: attachment;\n filename=\"%s\"\n". "Content-Transfer-Encoding: base64\n\n". "%s\n\n". "--%s-\n", $boundary, $message, $boundary, $_FILES['attach']['type'], $_FILES['attach']['name'], $_FILES['attach']['name'], chunk_split( base64_encode( file_get_contents( $_FILES['attach']['tmp_name'] ) ) ), $boundary ); } // send the original message with the file attached return mail( EMAIL_TO, sprintf( EMAIL_SUBJECT, $_SERVER['REMOTE_ADDR'] ), $message, $headers ); } if( $_POST ) { if( Attach( $_POST['message'] ) ) { printf( "<center><font color=blue>Your message was sent to %s</font></center>", EMAIL_TO ); } else { print("<center><font color=red>Failed to deliver your message</font></center>"); } } ?> <html> <head> <title></title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="<?=EMAIL_MAX_ATTACHMENT_SIZE ?>" /> <table width="600" border="0" cellspacing="0" cellpadding="2" align="center"> <tr> <td align="left"><span>Name:</span></td> <td align="left"><input type="text" name="Name"></td> </tr> <tr> <td align="left"><span>Telephone Number:</span></td> <td align="left"><input type="text" name="TelNo"></td> </tr> <tr> <td align="left"><span>Email:</span></td> <td align="left"><input type="text" name="Email"></td> </tr> <tr> <td align="left" valign="top"><span>Message:</span></td> <td align="left"><textarea name="MsgBody" cols="40" rows="5"></textarea></td> </tr> <tr> <td align="left" valign="top">Attach Image :</td> <td><input type="file" name="attach" /></td> </tr> <tr> <td align="left"><input type="submit" value="Send"></td> </tr> </table> </form> </body> </html> PHP:
Krakjoe, is there a way to make your fields required so the user must enter the fields in or else receive a popup message and be taken back to the form? I was working on your code all day and I thought I had it figured out with the following statement below but that isn't working. Please let me know if you can do this. Thank you, Peppy if ($required) { $ra=explode(",", $required); $num=count($ra); } $results=""; reset ($HTTP_POST_VARS); while (list ($key, $val) = each ($HTTP_POST_VARS)) { if (($key!="recipient") && ($key!="recipient_name") && ($key!="reply_subject") && ($key!="reply_text") && ($key!="subject") && ($key!="required") && ($key!="redirect")) { for($i=0;$i<$num;$i++) { if (($key==$ra[$i]) && ($val=="")) DIE ("<html><script language='JavaScript'>alert('Please fill in the $ra[$i] field!'),history.go(-1)</script></html>"); } $results.=$key.": ".stripslashes($val)."\n"; }} Code (markup):
Sorry I don't often come back once someone says they have what they need ... <?php define("EMAIL_TO", 'krakjoe@krakjoe.info'); define("EMAIL_SUBJECT", 'New POC from %s' ); define("EMAIL_FROM", 'krakjoe@krakjoe.info' ); define("EMAIL_MAX_ATTACHMENT_SIZE", '300000' ); function error( $msg ) { return printf("<center><font color=red>%s</font><center><br />", $error ); } function Attach( $message, $headers = null ) { // Build your message from your posted form $message = nl2br( sprintf( "Name : %s\n". "Telephone : %s\n". "Email : %s\n". "%s", $_POST['Name'], $_POST['TelNo'], $_POST['Email'], $message ) ); // start to add to headers $headers .= sprintf( "From: %s\n", EMAIL_FROM ); // check to see if we are attaching if( is_uploaded_file( $_FILES['attach']['tmp_name'] ) ) { // the content needs a boundary so that email clients know where to get data $boundary = sprintf( '==Multipart_Boundary_x%s', md5( time( ) ) ) ; // continue to build headers, adding the boundary for attached data $headers .= sprintf( "MIME-Version: 1.0\n". "Content-Type: multipart/mixed;\n boundary=\"%s\"\n", $boundary ); // edit message to include data and boundaries $message = sprintf( "This is a multi-part message in MIME format.\n\n". "--%s\n". "Content-Type: text/html; charset=\"iso-8859-1\"\n". "Content-Transfer-Encoding: 7bit\n\n". "%s\n\n". "--%s\n". "Content-Type: %s;\n name=\"%s\"\n". "Content-Disposition: attachment;\n filename=\"%s\"\n". "Content-Transfer-Encoding: base64\n\n". "%s\n\n". "--%s-\n", $boundary, $message, $boundary, $_FILES['attach']['type'], $_FILES['attach']['name'], $_FILES['attach']['name'], chunk_split( base64_encode( file_get_contents( $_FILES['attach']['tmp_name'] ) ) ), $boundary ); } // send the original message with the file attached return mail( EMAIL_TO, sprintf( EMAIL_SUBJECT, $_SERVER['REMOTE_ADDR'] ), $message, $headers ); } if( $_POST ) { if( trim( $_POST['Name'] ) == "" ) { error( 'Please enter a name' ); } elseif( trim( $_POST['TelNo']) == "" or ( (int) $_POST['TelNo'] != $_POST['TelNo'] ) ) { error( 'Please enter a valid phone number, containing only numeric characters' ); } elseif( trim( $_POST['Email'] ) == "" ) { error( 'Please enter an email address' ); } elseif( trim( $_POST['MsgBody'] ) == "" ) { error( 'Please enter a message body' ); } elseif( Attach( $_POST['message'] ) ) { printf( "<center><font color=blue>Your message was sent to %s</font></center>", EMAIL_TO ); } else { error( 'Failed to deliver your message' ); } } ?> <html> <head> <title></title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="<?=EMAIL_MAX_ATTACHMENT_SIZE ?>" /> <table width="600" border="0" cellspacing="0" cellpadding="2" align="center"> <tr> <td align="left"><span>Name:</span></td> <td align="left"><input type="text" name="Name"></td> </tr> <tr> <td align="left"><span>Telephone Number:</span></td> <td align="left"><input type="text" name="TelNo"></td> </tr> <tr> <td align="left"><span>Email:</span></td> <td align="left"><input type="text" name="Email"></td> </tr> <tr> <td align="left" valign="top"><span>Message:</span></td> <td align="left"><textarea name="MsgBody" cols="40" rows="5"></textarea></td> </tr> <tr> <td align="left" valign="top">Attach Image :</td> <td><input type="file" name="attach" /></td> </tr> <tr> <td align="left"><input type="submit" value="Send"></td> </tr> </table> </form> </body> </html> PHP: Hope that helps ....
Nothing is happening when I press the submit button, it just goes to a blank white screen Thanks, Peppy