PHP - Form To Send Email Attachment
Hi,
I've created a basic form which uploads a document to my server. How do I generate an email with the uploaded document as an attachment? Here's the HTML: <form enctype="multipart/form-data" action="form1.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> Here's the PHP: <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Thanks in advance! Similar TutorialsInterested to find out why this code doesn't seem to properly send the attachment.. it's driving my insane ? Code: [Select] <?php //define the receiver of the email $to = 'youraddress@example.com'; //define the subject of the email $subject = 'Test email with attachment'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: application/zip; name="attachment.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> I'm trying to after submission
1. create a csv
2. insert record into db
3. send email that's created in form submission - $msg.
4. send email with attachment to only the email I specify (if possible)
if not attach it to the email that's created at submission.
I've search and search and found different methods but doesn't work with my code.
I kept 3 lines at the top but can't get them to work ... either I don't get an email after submission or don't get an attachement.
Can some one help?
<?php $random_hash = md5(date('r', time())); $csvString = "..."; // your entire csv as a string $attachment = chunk_split(base64_encode($csvString)); $to = "email@email.com"; if(isset($_POST['submit'])) { // VALIDATION if(empty($_POST['firstName'])) { "First Name Required"; } if(empty($_POST['lastName'])) { "Last Name Required"; } if(empty($error)) { $to = "$to"; $subject = 'The Form'; $headers = "MIME-Version: 1.0 \r\n"; $headers .= "Content-Type: text/html; \r\n" ; $msg .="<html> <head></head> <body> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td> <table width='100%' cellspacing='0' border='0' cellpadding='0'> <tr><td>This is the email sent.</td></tr> </table> </body> </html>"; include('con.php'); $con = mysqli_connect($host,$user,$pass,$dbName); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"thetable"); $firstName = mysqli_real_escape_string($con, $_POST['firstName']); $lastName = mysqli_real_escape_string($con, $_POST['lastName']); $sql = "SELECT * FROM thetable WHERE `firstName` = '{$firstName}' OR `lastName` = '{$lastName}'"; $result = mysqli_query($con,$sql); if(($result->num_rows)>= 1) { $theerror = "You exist"; } else { $sql="INSERT INTO thetable(firstName, lastName) VALUES ('$_POST[firstName]','$_POST[lastName]'"; $success = "Sent ... Insert it!!!"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } $result = @mail($to, $subject, $msg, $headers); } mysqli_close($con); { } } } ?> Edited by barkly, 27 October 2014 - 02:59 PM. I would like to store PDF file into mysql (this part works) and then send it as email attachment and it should be retrieved from mysql table. Here's the code I have for now, but what it gives me is 0bytes large PDF file Saving PDF to mysql (it works), because size of blob in mysql table is OK. $fp = fopen('generated.pdf', 'r'); $content = fread($fp,filesize('generated.pdf')); $content = addslashes($content); fclose($fp); $DB->Query('insert into pdf_files (pdf_file, name) values ("'.$content.'", "'.$name.'")'); And here's the mailing part <?php $query = "SELECT name, pdf_file FROM pdf_files $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array ( $result)) { $fileContent =$row['pdf_file']; $fileName=$row['name']; } $fileatt = $fileContent; // getting file $fileatt_type ="application/pdf"; //type of file $fileatt_name = "attachment.pdf"; // name $fileatt_size = $fileSize; $email_from = "dont@have.it"; // mail from $email_subject = "Testtt"; // subject $email_message = "Testtt.<br>"; $email_message .= "Testtt.<br>"; // Message $email_to = $mail_user; // users mail $headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "Testtt.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message .= "\n\n"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data .= "\n\n" . "--{$mime_boundary}--\n"; $ok = @mail($email_to, $email_subject, $email_message, $headers); if($ok) { echo "<font face=verdana size=2><center>Mail was sent</center>"; } else { die("Error!"); } ?> I'm pretty new to PHP, and by new, I mean I have never done it or any other form of coding before starting my job a month or so ago. I've basically been manually trying to pick up PHP as I go. The website that I am working on had its core built, but I am trying to add functionality to it. The website already had the contact for that you can see he http://www.janova.us/index.php/contact The form would submit an email to an email address based on which subject was picked. I have since added a simple file upload field. My problem, however, is tying in the form to the email. I need to upload it and then send it as an attachment with the email. Here is what I am working with currently: <div id="breadCrumbs"> <a href="index.php">MAIN</a> > <a href="index.php/contact">CONTACT</a> </div> <? $user =& JFactory::getUser(); $user_id = $user -> get('id'); $user_name = $user -> get('name'); $db = JFactory::getDBO(); $query = "SELECT jos_content.introtext, jos_content.fulltext FROM jos_content WHERE catid = 68 AND sectionid = 5 LIMIT 0,3"; $db->setQuery($query); $rows = $db->loadRowList(); ?> <div id="contactTop"> <div id="contactBanner"></div> <div id="contactInfo"> <? echo $rows[0][0]; echo $rows[0][1]; ?> </div> </div> <div id="contactGreeting"> <? echo $rows[1][0]; echo $rows[1][1]; ?> </div> <? if($user_id > 0) { $query = "SELECT jos_users.name, jos_users.email FROM jos_users WHERE id = ".$user_id; $db->setQuery($query); $user_data = $db->loadRow(); } if(isset($_POST["submit"])) { $error = false; $subjectError = false; $messageError = false; $nameError = false; $emailError = false; if(!isset($_POST["subject"]) || empty($_POST["subject"])) { $error = true; $subjectError = true; } if(!isset($_POST["message"]) || empty($_POST["message"])) { $error = true; $messageError = true; } if(!isset($_POST["name"]) || empty($_POST["name"])) { $error = true; $nameError = true; } if(!isset($_POST["email"]) || empty($_POST["email"])) { $error = true; $emailError = true; } else if(!ereg("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$",$_POST["email"])) { $error = true; $emailError = true; echo $_POST["email"]; } if(!$error) { $to = $_POST["subject"]."@janova.us"; $from = $_POST["email"]; $subject = $_POST["subject"]." by: ".$_POST["name"]; $message = $_POST["subject"]."\n\r\n\r".$_POST["message"]."\n\r\n\r-".$_POST["name"]; $headers = "From: $from"; <!----------BEGIN ADDED CODE-------------------------> // Obtain file upload vars $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; } <!-----------END ADDED CODE----------------> mail($to,$subject,$message,$headers); echo "Your request has been submitted."; } else { ?> <form action="#" id="contactForm" method="post"> <div id="contactFormLeft"> <? if($user_id > 0) { ?> <label> Your name<? if($nameError) { ?><span class="formError">*</span><? }?> </label><br/> <input type="text" name="name" value="<?=$user_data[0];?>"/><br/> <label> Your email<? if($emailError) { ?><span class="formError">*</span><? }?> </label><br/> <input type="text" name="email" value="<?=$user_data[1];?>"/><br/> <? } else { ?> <label> Your name<? if($nameError) { ?><span class="formError">*</span><? }?> </label><br/> <input type="text" name="name" value="<?=$_POST["name"];?>"/><br/> <label> Your email<? if($emailError) { ?><span class="formError">*</span><? }?> </label><br/> <input type="text" name="email" value="<?=$_POST["email"];?>"/><br/> <? } ?> <label> Subject<? if($subjectError) { ?><span class="formError">*</span><? }?> </label><br/> <select name="subject"> <option value="support" <? if($_POST["subject"]=="support") { echo "selected ";}?>>Support</option> <option value="training" <? if($_POST["subject"]=="training") { echo "selected ";}?>>Training</option> <option value="hr" <? if($_POST["subject"]=="hr") { echo "selected ";}?>>HR</option> <option value="sales" <? if($_POST["subject"]=="sales") { echo "selected ";}?>>Consultation</option> </select> <br/> <input type="submit" id="submit" name="submit" value=""/><br/> </div> <div id="contactFormRight"> <label> Message<? if($messageError) { ?><span class="formError">*</span><? }?> </label><br/> <textarea name="message"><?=$_POST["message"];?></textarea><br/> </div> </form> <? } } else { ?> <!--Request More Info AKA Contact Page--> <!--Intro Text from Article--> <form action="#" id="contactForm" method="post"> <div id="contactFormLeft"> <? if($user_id > 0) { ?> <label> Your name </label><br/> <input type="text" name="name" value="<?=$user_data[0];?>"/><br/> <label> Your email </label><br/> <input type="text" name="email" value="<?=$user_data[1];?>"/><br/> <? } else { ?> <label> Your name </label><br/> <input type="text" name="name" value="<?=$_POST["name"];?>"/><br/> <label> Your email </label><br/> <input type="text" name="email" value="<?=$_POST["email"];?>"/><br/> <? } ?> <label> Subject </label><br/> <select name="subject"> <option value="support" <? if($_POST["subject"]=="support") { echo "selected ";}?>>Support</option> <option value="sales" <? if($_POST["subject"]=="sales") { echo "selected ";}?>>Consultation</option> <option value="training" <? if($_POST["subject"]=="training") { echo "selected ";}?>>Training</option> <option value="hr" <? if($_POST["subject"]=="hr") { echo "selected ";}?>>HR</option> </select> <br/> <input type="submit" id="submit" name="submit" value=""/> </div> <div id="contactFormRight"> <label> Message </label><br/> <textarea name="message"><?=$_POST["message"];?></textarea><br/> <!-----------ADDED FILE UPLOAD BOX ------------------> <label> Attach File: </label> <br/> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input type="file" name="fileatt" /> <br/> <!------------END FILE UPLOAD BOX---------------------> </div> </form> <? } ?> I have commented the changes I have added to the original code so that you can see what I have done. Any input on this would be greatly appreciated. Thanks. I am building a website that allows a client to email me documents (DocX, PDF, TXT,ZIP, etc) along with a simple HTML based form. I used DreamWeaver to create the form and the upload area. I figured out how to script the PHP code to send the text fields to my email address (and validate them), but I can't figure out how to get the attachments to send. I am BRAND NEW to PHP and just trying to figure all thing out. Any help would be appreciated. I have attached two .txt files to this post. One is the HTML code for the forum and one is the actual PHP code I am using to send the form to my email. Thanks for your help! [attachment deleted by admin] I am attempting to get my email form with file attachment to work. Apparently the file is not reaching getting to the validation portion of the page I have switched $_FILES['X'] on line 203 from file to fakefile as they are labeled in the form also I am employing css hacks to change the input file upload field to have a custom button example -> http://visualrealityink.com/dev/clients/arzan/snell_form_final/form.php here is my code I appreciate any help Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> #form_container{ display:block; position:absolute; width:610px; min-height:450px; background:#f8f8f8; padding: 5px 5px 5px 5px; font-family:Arial, Helvetica, sans-serif; font-size:14px; } #form { min-height:450px; width:100%; background:#ececec; padding:0 0 0 0; } #formheader { background:url(images/form2_08.png) no-repeat #2f2f2f; margin:0 0 0 0; padding:0 0 0 0; width:631; height:30px;} form{margin:35px 0 0 35px;} fieldset div { margin:0.3em 0; clear:both; } label { float:left; width:10em; text-align:left; margin-right:1em; font-family:Arial, Helvetica, sans-serif; font-size:14px; } input { padding:0.15em; margin:0 0 0 -110px; width:300px; background:url(images/inputbg.png) no-repeat; border:0px solid #ddd; background:#fafafa; -moz-border-radius:0.4em; -khtml-border-radius:0.4em; } .bg2{background:url(images/inputbg.png) no-repeat; height:28px; line-height:28px;} fieldset { border:0px solid #ddd; padding:0 0.5em 0.5em; margin:0 0 0 -100px; } #details{font-size:10px;} #logo{background:url(images/form2_11.png) no-repeat; width:189px; height:238px; margin:-200px 0 0 400px; position:absolute;} #submit{margin:14px 0 0 -5px; border:none; position:absolute; cursor:pointer; cursor:hand;} #reset{border:none; margin:14px 0 0 115px; position:absolute; cursor:pointer; cursor:hand; } #divinputfile{ background:url(images/form2_27.png) no-repeat 100% 1px; height:43px; line-height:43px; width:340px; }#divinputfile #filepc{ opacity: 0.0; -moz-opacity: 0.0; filter: alpha(opacity=00); font-size:18px; margin:0 0 0 0; cursor:hand; cursor:pointer; } #fakeinputfile{ margin-top:-28px; } #fakeinputfile #fakefilepc{ background:url(images/inputbg2.png) no-repeat; style:none; width:240px; height:28px; line-height:28px; border:0; margin:5px 0 0 0; font-size:18px; font-family:Arial; } button { cursor: hand; cursor: pointer; padding: 0px; margin: 0 0 0 0; } a.link_button{ cursor: hand; cursor: pointer; } .fileupload{ margin:0 0 0 50px; } input[type="file"] { cursor: pointer; } .error{font-size:9px; font-family:Arial, Helvetica, sans-serif; color:#F00; } .error ul { text-decoration: none; list-style: none; } .error li { color: #F00;} .captcha_form { margin: 0 0 0 -45px; width:235px; } #captchaimage{ padding:0 0 10px 0;} .small { font-size:9px;} </style> </head> <body> <?php if ($_POST['_submit_check']) { // If validate_form( ) returns errors, pass them to show_form( ) if ($form_errors = validate_form()) { show_form($form_errors); } else { // The submitted data is valid, so process it process_form(); } } else { // The form wasn't submitted, so display show_form(); } function show_form($errors = '') { // If the form is submitted, get defaults from submitted parameters if ($_POST['_submit_check']) { $defaults = $_POST; } else { // Otherwise, set our own defaults: medium size and yes to delivery $defaults = array('IssueDate' => '','ExpiryDate' => ''); } if ($errors) { $error_text = 'You need to correct the following errors:'; $error_text .= '<br /><ul>'; $error_text .= implode('<li>',$errors); $error_text .= '</li></ul>'; } else { // No errors? Then $error_text is blank $error_text = ''; } include 'formhelpers.php' ?> <div id="form_container"> <div id="form"> <br /> <div id="formheader"> </div> <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <span class="error"> <?php print $error_text ?> </span> <input type="hidden" name="_submit_check" value="1"/> <div> <label for="name">Name: </label> <?php input_text('name', $defaults) ?> </div> <div> <label for="email">Email:</label> <?php input_text('email', $defaults) ?> </div> <div> Attach Resume: <span class="small">(1MB : PDF : DOC : DOCX : TXT)</span> </div> <div> <!--<input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <label for="userfile"></label> <input type="file" name="userfile" id="userfile"/> </div>--> <div id="divinputfile"> <input name="file" type="file" size="30" id="filepc" onchange="document.getElementById('fakefilepc').value = this.value;"/> <div id="fakeinputfile"> <input name="fakefile" type="text" class="link_button" id="fakefilepc" /> </div> </div> <div id="captchaimage"><img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /></div> <div><label for="email"><a style="text-decoration: none" href="#" onclick="document.getElementById('captcha').src = 'securimage/securimage_show.php?' + Math.random(); return false">New Captcha: </a></label> <input type="text" name="captcha_code" class="captcha_form" size="10" maxlength="6" /> </div> <button type="submit" value="submit" id="submit" ><img src="images/form2_33.png" /></button> <button type="reset" value="reset" id="reset" ><img src="images/form2_37.png" /></button> </form> </div> <div id="logo"></div> </div> </div> <?php } function validate_form() { $errors = array( ); // name is required if ($_POST['name'] == "") { $errors[ ] = 'Please enter your name.'; } if (! strlen(trim($_POST['email']))) { $errors[ ] = 'Please enter your Email.'; } if (! preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $_POST['email'])) { $errors[ ] = 'Please enter a valid e-mail address'; } $filename=$_FILES['file']['name']; //For size if($_FILES["file"]["size"]>1000000) //1 mb { $errors[ ] = "File size should be less than 1MB"; } // for extention $ext = end(explode('.', $filename)); if($ext=='doc' || $ext=='txt' || $ext=='pdf' || $ext=='docx' ) { echo "write the code to upload file"; $max_allowed_file_size = 1024; // size in KB $name_of_uploaded_file = basename($_FILES['file']['name']); //get the file extension of the file $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["file"]["size"]/1024;//size in KBs //copy the temp. uploaded file to uploads folder $upload_folder = 'upload/'; $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; $tmp_path = $_FILES["file"]["tmp_name"]; if(is_uploaded_file($tmp_path)) { if(!copy($tmp_path,$path_of_uploaded_file)){ echo 'error while copying the uploaded file'; die(); } } } else { $errors[ ] = "Only doc or pdf or txt file is allowed: $filename "; } return $errors; } function process_form() { $image = "http://www.visualrealityink.com/dev/clients/arzan/snell_form/images/email.png"; include_once('Mail.php'); include_once('Mail_Mime/mime.php'); $to = 'george@visualrealityink.com'; $text = $image . "<br />" . $values['name'] . "submitted a resume on our website. Please review the applications and contact the candidate if their resume is a fit for any open opportunities with the company. <br><br> Thank you. <br><br> SEI Team"; $message=new Mail_mime(); $message=setTXTBody($text); $message=addAttachment($path_of_uploaded_file); $body = $message->get(); $extraheaders = array("From"=>$formValues['email'], "Subject"=>$subject, "Reply-To"=>$formValues['email']); $headers = $message->headers($extraheaders); $mail = Mail::factory("mail"); $mail->send($to, $headers, $body); echo "email sent"; } ?> </body> </html> Hi all, What I am trying to achieve is, I thought quite simple! Basically, a user signs up and chooses a package, form is submitted, details added to the database, email sent to customer, then I want to direct them to a paypal payment screen, this is where I am having issues! Is their any way in php to submit a form without user interaction? Here is my code for the form process page Code: [Select] <?php include('config.php'); require('scripts/class.phpmailer.php'); $package = $_POST['select1']; $name = $_POST['name']; $email = $_POST['email']; $password = md5($_POST['password']); $domain = $_POST['domain']; $a_username = $_POST['a_username']; $a_password = $_POST['a_password']; $query=mysql_query("INSERT INTO orders (package, name, email, password, domain, a_username, a_password) VALUES ('$package', '$name', '$email', '$password', '$domain', '$a_username', '$a_password')"); if (!$query) { echo "fail<br>"; echo mysql_error(); } else { $id = mysql_insert_id(); $query1=mysql_query("INSERT INTO customers (id, name, email, password) values ('$id', '$name', '$email', '$password')"); if (!$query1) { echo "fail<br>"; echo mysql_error(); } if($package=="Reseller Hosting") { //email stuff here - all works - just cutting it to keep the code short if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } ?> <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="subscription@jollyhosting.com"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_name" value="Jolly Hosting Reseller Packages"> <input type="hidden" name="no_shipping" value="1"> <!--1st month --> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="a3" value="3.00"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> <input type="hidden" name="sra" value="1"> </form>'; <?php } //last } //end ?> sendmail.php Code: [Select] <?php $email = $_POST['email']; $to = $_POST['recipent']; $subject = "SUBJECT HERE."; $message = "YOUR MESSAGE HERE"; $header = "From: $email " . "\r\n"; $send = mail($to, $subject, $message, $header); echo "Your invitations have been sent!"; ?> and this is invite.php Code: [Select] <style> #container_mail { width:300px; margin:0 auto; background:#151521; padding:5px; background-color:#ffffff; border:1px solid black; /* for IE */ filter:alpha(opacity=60); /* CSS3 standard */ opacity:0.6; } #inner_container_mail { background:url(../images/inner_container.jpg) top repeat-x #181824; padding:10px 10px 10px 25px; } </style> <?php include_once 'common.php'; require_once("pages/validation.php"); ?> <script type="text/javascript" src="ajax/jquery.js"></script> <div id="container_mail"> <div id="inner_container_mail"> <div id="content"> <?if( isset($_POST['send']) && (!validateEmail($_POST['email']) ) ):?> <div id="error"> <ul> <?if(!validateEmail($_POST['email'])):?> <li><strong><?=$errormail?></strong> <?=$errormail1?></li> <?endif?> </ul> </div> <?elseif(isset($_POST['send'])):?> <div id="error" class="valid"> <ul> <li><strong><?=$congratulations?></strong> <?=$congratulations?></li> </ul> </div> <p> <?endif?> </p> <form method="post" id="customForm" action="pages/invite_mail.php"> <div> <label for="email"><?= $email; ?></label> <input id="email" name="email" type="text" /> <span id="emailInfo"><?= $yourmail; ?></span> </div> <div> <label for="recipent"><?= $email; ?></label> <input id="recipent" name="recipent" type="text" /> <span id="emailInfo"><?= $yourmail; ?></span> </div> <div> <input id="send" name="send" type="submit" value="<?=$submit;?>" /> </div> </form> </div> <script type="text/javascript" src="ajax/jquery.js"></script> <script type="text/javascript" src="ajax/validation_email.js"></script> </body> </html> </div> </div> </div> </body> </html> how to send the corent location in website to friend for example now my location is http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 how to send this ? sorry for my english .. I am stumped here, can not figure out a efficient way to collect all the data on this page and send it to my to user's id number. I am trying to format the email to include question #1 and then next to it radio1 (answer yes/no) , question#2 and so on followed by the viewers input from the last part of the form. Does any one know of some thing im missing here? <?php session_start(); // If the session vars aren't set, try to set them with a cookie if (!isset($_SESSION['user_id'])) { if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) { $_SESSION['user_id'] = $_COOKIE['user_id']; $_SESSION['username'] = $_COOKIE['username']; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Social Filter - View Profile</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h3>View Profile</h3> <font size="2"> <?php require_once('appvars.php'); require_once('connectvars.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<a href="signup.php">Create your own account</a>.</p>'; } else { echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>'); } // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['user_id'])) { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20 FROM mismatch_user WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20 FROM mismatch_user WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo '<table cellpadding="0" cellspacing="0" border="0"><TR><TD> '; if (!empty($row['picture'])) { echo '<table cellpadding="0" cellspacing="0" border="1"><TR><td class="label">Pictu </td><td><img src="' . MM_UPLOADPATH . $row['picture'] . '" width="120" height="140" alt="Profile Picture" /></td></tr></table></td><td>'; } if (!empty($row['username'])) { echo '<table cellpadding="1" cellspacing="0" border="0"><TR><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>'; } if (!empty($row['first_name'])) { echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></TR>'; } if (!empty($row['last_name'])) { echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></TR>'; } if (!empty($row['gender'])) { echo '<tr><td class="label">Gender:</td><td>'; if ($row['gender'] == 'M') { echo 'Male'; } else if ($row['gender'] == 'F') { echo 'Female'; } else { echo '?'; } echo '</td></tr>'; } if (!empty($row['birthdate'])) { if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) { // Show the user their own birthdate echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>'; } else { // Show only the birth year for everyone else list($year, $month, $day) = explode('-', $row['birthdate']); echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>'; } } if (!empty($row['city']) || !empty($row['state'])) { echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . '</td></tr>'; } echo '</td></tr></table></td></Tr></table><hr></font><FONT color="#666666" size="1" face="Courier"><table cellpadding="20" cellspacing="0" border="0"><tr><td>'; if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) { echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } if (!empty($row['q1'])) { echo '1. ' . $row['q1'] . '<BR><input type="radio" name="radio1" id="yes1" value="yes" /> <label for="yes1">YES</label> or <input type="radio" name="radio1" id="no1" value="no" /> <label for="no1">NO</label><BR>'; } else { echo ' User has not made a application yet...<BR>'; } if (!empty($row['q2'])) { echo '2. ' . $row['q2'] . '<BR><input type="radio" name="radio2" id="yes2" value="yes" /> <label for="yes2">YES</label> or <input type="radio" name="radio2" id="no2" value="no" /> <label for="no2">NO</label><BR>'; } else { echo ' <BR>'; } if (!empty($row['q3'])) { echo '3. ' . $row['q3'] . '<BR><input type="radio" name="radio3" id="yes3" value="yes" /> <label for="yes3">YES</label> or <input type="radio" name="radio3" id="no3" value="no" /> <label for="no3">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q4'])) { echo '4. ' . $row['q4'] . '<BR><input type="radio" name="radio4" id="yes4" value="yes" /> <label for="yes4">YES</label> or <input type="radio" name="radio4" id="no4" value="no" /> <label for="no4">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q5'])) { echo '5. ' . $row['q5'] . '<BR><input type="radio" name="radio5" id="yes5" value="yes" /> <label for="yes5">YES</label> or <input type="radio" name="radio5" id="no5" value="no" /> <label for="no5">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q6'])) { echo '6. ' . $row['q6'] . '<BR><input type="radio" name="radio6" id="yes6" value="yes" /> <label for="yes6">YES</label> or <input type="radio" name="radio6" id="no6" value="no" /> <label for="no6">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q7'])) { echo '7. ' . $row['q7'] . '<BR><input type="radio" name="radio7" id="yes7" value="yes" /> <label for="yes7">YES</label> or <input type="radio" name="radio7" id="no7" value="no" /> <label for="no7">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q8'])) { echo '8. ' . $row['q8'] . '<BR><input type="radio" name="radio8" id="yes8" value="yes" /> <label for="yes8">YES</label> or <input type="radio" name="radio8" id="no8" value="no" /> <label for="no8">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q9'])) { echo '9. ' . $row['q9'] . '<BR><input type="radio" name="radio9" id="yes9" value="yes" /> <label for="yes9">YES</label> or <input type="radio" name="radio9" id="no9" value="no" /> <label for="no9">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q10'])) { echo '10. ' . $row['q10'] . '<BR><input type="radio" name="radio10" id="yes10" value="yes" /> <label for="yes10">YES</label> or <input type="radio" name="radio10" id="no10" value="no" /> <label for="no10">NO</label><BR></td><TD>'; } else { echo '<BR></td><td>'; } if (!empty($row['q11'])) { echo '11. ' . $row['q11'] . '<BR><input type="radio" name="radio11" id="yes11" value="yes" /> <label for="yes11">YES</label> or <input type="radio" name="radio11" id="no11" value="no" /> <label for="no11">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q12'])) { echo '12. ' . $row['q12'] . '<BR><input type="radio" name="radio12" id="yes12" value="yes" /> <label for="yes12">YES</label> or <input type="radio" name="radio12" id="no12" value="no" /> <label for="no12">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q13'])) { echo '13. ' . $row['q13'] . '<BR><input type="radio" name="radio13" id="yes13" value="yes" /> <label for="yes13">YES</label> or <input type="radio" name="radio13" id="no13" value="no" /> <label for="no13">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q14'])) { echo '14. ' . $row['q14'] . '<BR><input type="radio" name="radio14" id="yes14" value="yes" /> <label for="yes14">YES</label> or <input type="radio" name="radio14" id="no14" value="no" /> <label for="no14">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q15'])) { echo '15. ' . $row['q15'] . '<BR><input type="radio" name="radio15" id="yes15" value="yes" /> <label for="yes15">YES</label> or <input type="radio" name="radio15" id="no15" value="no" /> <label for="no15">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q16'])) { echo '16. ' . $row['q16'] . '<BR><input type="radio" name="radio16" id="yes16" value="yes" /> <label for="yes16">YES</label> or <input type="radio" name="radio17" id="no16" value="no" /> <label for="no16">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q17'])) { echo '17. ' . $row['q17'] . '<BR><input type="radio" name="radio17" id="yes17" value="yes" /> <label for="yes17">YES</label> or <input type="radio" name="radio17" id="no17" value="no" /> <label for="no17">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q18'])) { echo '18. ' . $row['q18'] . '<BR><input type="radio" name="radio18" id="yes18" value="yes" /> <label for="yes18">YES</label> or <input type="radio" name="radio18" id="no18" value="no" /> <label for="no18">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q19'])) { echo '19. ' . $row['q19'] . '<BR><input type="radio" name="radio19" id="yes19" value="yes" /> <label for="yes19">YES</label> or <input type="radio" name="radio19" id="no19" value="no" /> <label for="no19">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q20'])) { echo '20. ' . $row['q20'] . '<BR><input type="radio" name="radio20" id="yes20" value="yes" /> <label for="yes20">YES</label> or <input type="radio" name="radio20" id="no20" value="no" /> <label for="no20">NO</label><BR></td><td></font></font>'; } else { echo '<BR></td><td valign="top"></font></font><FONT color="#000000" size="1">'; } mysqli_close($dbc); ?> <script> function autotab(original,destination){ if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus() } </script> <fieldset> <legend>Your Contact Information</legend> </font></font><FONT color="#cccc99" size="2" face="Impact"> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table width="100%" border="0" cellpadding="2"> <tr> <td><div align="right"> <label for="vieweremail">Email</label> </div></td> <td><div align="left"> <input name="vieweremail" type="text" id="vieweremail" size="35" maxlength="90" /> </div></td> </tr> <tr> <td><div align="right"> <label for="veiwername">Name</label> </div></td> <td><div align="left"> <input name="veiwername" type="text" id="veiwername" size="35" maxlength="100" /> </div></td> </tr> <tr> <td><div align="right"> <label for="viewerphone">Phone Number</label> </div></td> <td><div align="left"> <input name="Phone1" type="text" id="phone1" onkeyup="autotab(this, document.form1.phone2)" size="3" maxlength="3" /> <input name="phone2" type="text" id="phone2" onKeyup="autotab(this, document.form1.phone3)" size="3" maxlength="3" /> <input name="phone3" type="text" id="phone3" onKeyup="autotab(this, document.form1.viewercomments)" size="4" maxlength="4" /> </div></td> </tr> <tr> <td><div align="right"> <label for="viewercomments">Comments</label> </div></td> <td><div align="left"> <textarea name="viewercomments" cols="26" rows="4" id="viewercomments"></textarea> </div></td> </tr> <tr> <td><div align="right"> <label for="viewerpic">Your Picture (optional)</label> </div></td> <td><div align="left"> <input name="viewerpic" type="file" id="viewerpic" size="22" /> </div></td> </tr> <tr> <td><div align="right"> <label for="clear"></label> <input type="reset" name="clear" id="clear" value="Clear Form!" /> </div></td> <td><div align="left"> <label for="submit"></label> <input type="submit" name="submit" id="submit" value="Send Email" /> </div></td> </tr> </table> </form> </fieldset> <BR><BR><BR><BR><BR><BR> </td></tr></table> </body> </html> Here is the send mail script im using.... trying to anyways.<?php require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { $from = 'cupid@cupidsomething.com'; $subject = $_POST['subject']; $text = $_POST['q1, q2,q3,q4....ect...etc....cet.....eece.c.']; $output_form = false; if (empty($subject) && empty($text)) { echo 'You forgot the email subject and body text.<br />'; $output_form = true; } if (empty($subject) && (!empty($text))) { echo 'You forgot the email subject.<br />'; $output_form = true; } if ((!empty($subject)) && empty($text)) { echo 'You forgot the email body text.<br />'; $output_form = true; } } else { $output_form = true; } if ((!empty($subject)) && (!empty($text))) { $query = "SELECT user_id FROM email_list WHERE user_id = '$user_id'; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)){ $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = "Dear $first_name $last_name,\n$text"; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $first_name . '<br />'; } mysqli_close($dbc); } if ($output_form) { ?> Any help would be greeeeatly appreciated. Here is a live example of this at www.interestingspecies.com/mismatch/20 Hi. I'm having some problem with my form. I want to create a booking form with the attachment. Its done but have a few error. Anyone can help me? If the form goes to my email, I can download the attachment. but if i want to open it, it will show this error.'Unable to upen the file. Not a valid PDF file.' Beside that, after i submit the form, this error will come out at my form. Warning: fclose(): supplied argument is not a valid stream resource in D:\xampplite\htdocs\borneotours02\booking2.php on line 268 This is my code: <? require_once("Connections/pamconnection.php"); $cart_id=session_id(); if($_POST['Submit']=='Submit'){ if(mysql_query("INSERT INTO inquiry_log1 (id, session_id, tour, name, contact, email02, phone, fax, travel, adult, children, p_requirement, foc, pdf_title, itinerary,, status, date_posted, time) VALUES ('', '".$cart_id."', '".mysql_real_escape_string($_POST['tour'])."', '".mysql_real_escape_string($_POST['name'])."', '".mysql_real_escape_string($_POST['contact'])."', '".mysql_real_escape_string($_POST['email02'])."', '".mysql_real_escape_string($_POST['phone'])."', '".mysql_real_escape_string($_POST['fax'])."', '".mysql_real_escape_string($_POST['travel'])."', '".mysql_real_escape_string($_POST['no_adult'])."', '".mysql_real_escape_string($_POST['no_children'])."', '".mysql_real_escape_string($_POST['product_requirement'])."', '".mysql_real_escape_string($_POST['foc_allocation'])."', '".mysql_real_escape_string($_POST['pdf_file'])."', '".mysql_real_escape_string($_POST['itinerary'])."', 1, '".date("Y-m-d")."', '".date("g:i a")."')")) if($_FILES['pdf_file']!='') { $fileatt = $HTTP_POST_FILES['pdf_file']['tmp_name']; $fileatt_type = $HTTP_POST_FILES['pdf_file']['type']; $file_name = $HTTP_POST_FILES['pdf_file']['name']; $ext = substr(strrchr($fileatt_type, "/"), 1); switch ( $ext ) { case 'pdf': $fileatt_name = $file_name; break; case 'msword': $fileatt_name = $file_name; break; case 'vnd.openxmlformats-officedocument.wordprocessingml.document': $fileatt_name = $file_name; break; } } $email_from = $_POST['email02']; // Who the email is from $email_subject = "Outbound Booking Form"; // The Subject of the email $email_message.='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <!--<style> .title{ font-family:Verdana, Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold; } .content{ font-family:Verdana, Arial, Helvetica, sans-serifl; font-size:12px;} </style>--> <body> <table width="600" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000"> <tr><td> <table width="100%" border="0" align="center" cellpadding="4" cellspacing="6" bgcolor="#DCE1E9" class="content"> <tr> <td colspan="2" class="title">Online Booking Form</td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" align="right">'.date("jS F Y").'</td> </tr> <tr class="style9"> <td> </td> </tr>'; if($_POST['tour']!=''){ $email_message.='<tr class="style9"> <td width="32%" class="title02">Tour Package Name</td> <td width="68%" class="email_message">'.$_POST['tour'].'</td> </tr>';} //if($_POST['title']!=''){ //$email_message.='<tr class="style9"> //<td width="32%" class="title02">Title</td> //<td width="68%" class="email_message">'.$_POST['title'].'</td> //</tr>';} $email_message.=' <tr class="style9"><td colspan="2" class="title" bgcolor="#FFFFFF"><strong>CONTACT DETAILS</strong></td></tr>'; if($_POST['name']!=''){ $email_message.='<tr class="style9"> <td width="32%" class="title02">Name</td> <td width="68%" class="email_message">'.$_POST['name'].'</td> </tr>';} if($_POST['contact']!=''){ $email_message.='<tr class="style9"> <td class="title02">Contact Person</td> <td class="email_message">'.$_POST['contact'].'</td> </tr>';} if($_POST['email02']!=''){ $email_message.='<tr class="style9"> <td class="title02">Email Address</td> <td class="email_message">'.$_POST['email02'].'</td> </tr>';} if($_POST['phone']!=''){ $email_message.='<tr class="style9"> <td class="title02">Phone Number</td> <td class="email_message">'.$_POST['phone'].'</td> </tr>';} if($_POST['fax']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Fax Number</td> <td class="email_message">'.$_POST['fax'].'<br><br></td> </tr>';} $email_message.=' <tr class="style9"><td colspan="2" class="title" bgcolor="#FFFFFF"><strong>TRIP REQUIREMENTS</strong></td></tr>'; if($_POST['travel']!=''){ $email_message.='<tr class="style9"> <td class="title02">Date Of Travel</td> <td class="email_message">'.$_POST['travel'].'</td> </tr>';} $email_message.=' <tr class="style9"><td colspan="2" class="title02">No.Of Travellers :</td></tr>'; if($_POST['adult']!=''){ $email_message.='<tr class="style9"> <td class="title02">Adults</td> <td class="email_message">'.$_POST['adult'].'</td> </tr>';} if($_POST['children']!=''){ $email_message.='<tr class="style9"> <td width="32%" valign="top" class="title02">Children</td> <td width="68%" class="email_message">'.$_POST['children'].'</td> </tr>';} if($_POST['s_interest']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Special Interest</td> <td class="email_message">'.$_POST['s_interest'].'</td> </tr>';} if($_POST['p_requirement']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Product Requirement</td> <td class="email_message">'.$_POST['p_requirement'].'</td> </tr>';} if($_POST['foc']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">FOC Allocation</td> <td class="email_message">'.$_POST['foc'].'<br><br></td> </tr>';} $email_message.=' <tr class="style9"><td colspan="2" class="title02">Room Types Required:</td></tr>'; if($_POST['single']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Single</td> <td class="email_message">'.$_POST['single'].'</td> </tr>';} if($_POST['double']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Double</td> <td class="email_message">'.$_POST['double'].'</td> </tr>';} if($_POST['triple']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Triple</td> <td class="email_message">'.$_POST['triple'].'</td> </tr>';} if($_POST['s_requirement']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Special Requirement</td> <td class="email_message">'.$_POST['s_requirement'].'<br><br></td> </tr>';} $email_message.=' <tr class="style9"><td colspan="2" class="title" bgcolor="#FFFFFF"><strong>ITINERARY</strong></td></tr>'; if($_POST['pdf_file']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Itinerary File</td> <td class="email_message">'.$_POST['pdf_file'].'</td> </tr>';} if($_POST['itinerary']!=''){ $email_message.='<tr class="style9"> <td valign="top" class="title02">Itinerary</td> <td class="email_message">'.$_POST['itinerary'].'<br><br></td> </tr>';} $email_message.='<tr class="style9"> <td colspan="2" valign="top"><div align="center"> </div></td> </tr> </table> </td></tr></table></body> </html>'; $email_to = "ee_elizebert@hotmail.com"; // Who the email is to ini_set(SMTP, "mail.sarawakhost.com"); ini_set(smtp_port, "587"); ini_set(sendmail_from, $email); $headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); //$data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message .= "\n\n"; $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data .= "\n\n" . "--{$mime_boundary}--\n"; $ok = mail($email_to, $email_subject, $email_message, $headers); if($ok) { $send='<font color=#336600>Feedback sent</font>'; } else { $send='<font color=#CC3300>Failed to send. Please try again.</font>'; } }?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Outbound Booking Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .style1 {color: #FF0000} body { background-image: url(images/booking.jpg); background-repeat:repeat-x; } --> </style> </head> <script> function booknow() { if(document.form1.name.value==''){alert("Please enter your name. Thank You."); document.form1.name.focus(); return false;} if(document.form1.contact.value==''){alert("Please enter the contact person. Thank You."); document.form1.contact.focus(); return false;} if(document.form1.email02.value==''){alert("Please enter your email address. Thank You."); document.form1.email02.focus(); return false;} if(document.form1.email02.value.indexOf('@')==-1){alert("Invalid email address. Please enter a valid email address. Thank You."); document.form1.email02.focus(); return false;} if(document.form1.email02.value.indexOf('.')==-1){alert("Invalid email address. Please enter a valid email address. Thank You."); document.form1.email02.focus(); return false;} } //<![CDATA[ window.addEvent('domready', function() { myCal2 = new Calendar({ date02: 'd/m/Y' }, { classes: ['dashboard'], direction: 1, tweak: {x: 3, y: -3} }); }); window.addEvent('domready', function() { myCal2 = new Calendar({ date03: 'd/m/Y' }, { classes: ['dashboard'], direction: 1, tweak: {x: 3, y: -3} }); }); //]]> </script> <script type="text/javascript" src="mootools.v1.11.js"></script> <script type="text/javascript" src="DatePicker.js"></script> <script type="text/javascript"> window.addEvent('domready', function(){ $$('input.DatePicker').each( function(el){ new DatePicker(el); }); }); </script> </script> <link rel="stylesheet" type="text/css" href="DatePicker.css" media="screen" /> <link rel="stylesheet" type="text/css" href="css/iframe.css" media="screen" /> <link rel="stylesheet" type="text/css" href="css/dashboard.css" media="screen" /> <link href="css.css" rel="stylesheet" type="text/css" /> <? if($send!=''){?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><? echo $send?></td> </tr> </table> <? }?> <form name="form1" method="post" action="booking2.php" enctype="multipart/form-data"> <table width="100%" border="0" cellspacing="4" cellpadding="2"> <tr> <td align="left" valign="middle" colspan="2"><p class="title3"><? echo $send;?></td> </tr> <tr> <td align="left" valign="middle" colspan="2"><? include("form_feature_tools.php");?></td> </tr> <table width="100%" border="0"> <tr> <td width="17%"><div align="right" class="title6"><strong>Tour Package Name</strong></div></td> <td width="28%"><span class="heading4"><? echo $_GET['tour']; if($_GET['code']!='') echo " (".$_GET['code'].")";?> <input type="hidden" name="tour" value="<? echo $_GET['tour']; if($_GET['code']!='') echo " (".$_GET['code'].")";?>" /> </span></td> <td width="16%"> </td> <td width="39%"> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="right"><strong class="title6">CONTACT DETAILS</strong></div></td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="right"><span class="title6">Name</span> <span class="content_text3">*</span></div></td> <td><div align="left"><span class="title6"> <input name="name" type="text" class="style7" id="name" size="30" value="<? echo $_POST['name']?>" /> </span></div></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right"><span class="title6">Contact Person</span><span class="content_text3">*</span></div></td> <td><div align="left"><span class="title6"> <input name="contact" type="text" class="style7" id="contact" size="30" value="<? echo $_POST['contact']?>"/> </span></div></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="title6">Email Address <span class="content_text3">*</span></div></td> <td><div align="left"> <input name="email02" type="text" class="style7" id="email02" size="30" value="<? echo $_POST['email02']?>" /> </div></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="title6">Phone Number</div></td> <td><div align="left"> <input type="text" name="phone" id="phone" class="style7" value="<? echo $_POST['phone']?>"/> </div></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="title6">Fax Number</div></td> <td><div align="left"> <input type="text" name="fax" id="fax" class="style7" value="<? echo $_POST['fax']?>"/> </div></td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="right"><strong class="title6">TRIP REQUIREMENTS</strong></div></td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="title6">Date Of Travel : </div></td> <td><? echo '<input id="travel" name="travel" style="width:50%" type="text" class="DatePicker" tabindex="1" value="'.date("m/d/Y", $tomorrow).'"/>';?></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="title6" valign="top">No Of Travellers: </div></td> <td><table width="100%" border="0"> <tr> <td width="19%" class="title6"><div align="right">Adult:</div></td> <td width="81%"><div align="left"> <input type="text" name="no_adult" id="no_adult" value="<? echo $_POST['adult']?>" /> </div></td> </tr> <tr> <td><div align="right" class="title6">Children:</div></td> <td><div align="left"> <input type="text" name="no_children" id="no_children" value="<? echo $_POST['children']?>"/> </div></td> </tr> </table></td> <td><div align="right" class="title6" valign="top">Product Requirement: </div></td> <td> <table width="41%" border="0"> <tr> <td width="8%"><input type="radio" name="product_requirement" id="air" value="air and land" <? if($_POST['p_requirement']=="air"){?> selected="selected"<? }?>/></td> <td width="92%" class="title6"><div align="left">Air & Land</div></td> </tr> <tr> <td><input type="radio" name="product_requirement" id="land" value="land only" <? if($_POST['p_requirement']=="land"){?> selected="selected"<? }?> /></td> <td class="title6"><div align="left">Land Only</div></td> </tr> </table></td> </tr> <tr> <td class="title6"><div align="right">Special Interest:</div></td> <td><div align="left"> <textarea name="special_interest" id="special_interest" cols="30" rows="3"><? echo $_POST['s_interest']?></textarea> </div></td> <td><div align="right" valign="top" class="title6">FOC Allocation</div></td> <td><div align="left"> <input type="text" name="foc_allocation" id="foc_allocation" value="<? echo $_POST['foc']?>"/> </div></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td class="title6"><div align="right"><strong>ITINERARY</strong></div></td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="title6">Upload Itinerary</div></td> <td><div align="left"> <input name="pdf_file" enctype="multipart/form-data" type="file" id="pdf_file"> <br> <span class="content_text">Browse for file (.doc or .pdf only)</span></div></td> <td> </td> <td> </td> </tr> <tr> <td><div align="right" class="title6">or ENTER Itinerary Here;</div></td> <td> <label> <div align="left"> <textarea name="itinerary" id="itinerary" cols="30" rows="3"><? echo $_POST['itinerary']?></textarea> </div> </label></td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><div align="right"> <input name="reset" type="reset" id="reset" value="Reset"/> </div></td> <td><div align="left"> <input type="Submit" name="Submit" value="Submit" onClick="return booknow();" /> </div></td> <td> </td> </tr> </table> </body> </html> I am brand new at php coding so I am struggling to understand why my php code is not working in my website. I would like my html form to send me data to my email. Whatever I try, it just will not work. I have ftp'ed it to my website and I checked with my web host, they do support php. Anyone who can help out a newbie, please?
This is my very simple form to capture email addresses of new clients: <form action="send_mail.php" method="post"> <input name="Email"
placeholder="Enter your email..." required="" type="email"> This is the php coding I have placed in a document called send_mail.php:
<?php /* Code: [Select] <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $dropdown = $_POST['dropdown']; $formcontent=" From: $firstname \n Surname: $lastname \n Email: $email \n Dropdown: $dropdown"; $recipient = "martin@sittingspiritually.co.uk, siobhan@sittingspiritually.co.uk"; $subject = "Newsletter Sign Up"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); if ( mail($recipient, $subject, $formcontent, $mailheader) ){ header('Location: http://www.sittingspiritually.co.uk/thankyou.php'); } else { die ("error"); } ?> I have recently created a small snippet of php code for posting mail and it's sweet apart from 1 thing. I have two email addresses in the recipient section. It only sends to the last name in the list. Is this because i have written recipient? Should it be recipients? I need this mail to be delivered to both of the email addresses. I'm sure it's simple for someone with expert knowledge. Thanks in advance for any help. I have a contact form with a file upload button, when you click on “submit” you are redirected on Paypal everything works fine but, I would like to send the contact form only when visitors have paid on Paypal. I’ve searched on google but I have not found a way to do this. Can anyone help? Cheers, Aidan. if anyone out there fancy's helping the needy please can you cast your eyes over my mess! and possibly help me find my way out of this maze? So im useing a third party form, and a third party php script.......... cant get them to work together . form script : [color=red//-------------------------------------------------[/color] <form action="phpquote.php" method="post" id="reserve-form"> <div class="box"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="border-top"></div> </div> </div> <div class="border-left"> <div class="border-right"> <div class="xcontent"> <h5>Get an online quote for your journey</h5> <p>please fill in all fields for your quote.</p> <fieldset> <div class="field"> <label>Customer Information</label> <input type="text" id="name" value="Name" onblur="if(this.value==''){this.value='Name'}" onfocus="if(this.value=='Name'){this.value=''}" /> </div> <div> <input type="text" id="number" value="Phone" onblur="if(this.value==''){this.value='Phone'}" onfocus="if(this.value=='Phone'){this.value=''}" /> </div> </fieldset> <fieldset class="style1"> <div class="field"> <label>Travel Date/ Time</label> <select id="year"> <option>2010</option> <option>2011</option> </select> <select class="sel-1" id="month"> <option>Jan</option> <option>Feb</option> <option>Mar</option> <option>Apr</option> <option>May</option> <option>Jun</option> <option>Jul</option> <option>Aug</option> <option>Oct</option> <option>Sep</option> <option>Nov</option> <option>Dec</option> </select> <select class="sel-2" id="date"> <option>1</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> </select> </div> <div class="field"> <select class="sel-2" id="time"> <option>00</option> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option></select> <select class="sel-2" id="time"> <option>00</option> <option>15</option> <option>30</option> <option>45</option> </select> </div> <div class="field"> <label>No. Passangers</label> <select id="year"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> </select> </div> </fieldset> <fieldset class="style2"> <div class="field"> <label>Pickup Information</label> <input type="text" id="where" value="Pickup Address" onblur="if(this.value==''){this.value='Pickup Address'}" onfocus="if(this.value=='Pickup Address'){this.value=''}" /> </div> <div> <select id="where"> <option>or Airport</option> <option>Stansted</option> <option>Gatwick</option> <option>Heathrow</option> <option>Luton</option> </select> </div> </fieldset> <fieldset class="style2 style3"> <div class="field"> <label>Drop-off Information</label> <input type="text" id="to" value="Drop-off Address" onblur="if(this.value==''){this.value='Drop-off Address'}" onfocus="if(this.value=='Drop-off Address'){this.value=''}" /> </div> <div> <select id="to"> <option>or Airport</option> <option>Stansted</option> <option>Gatwick</option> <option>Heathrow</option> <option>Luton</option> </select> </div> </fieldset> </div> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"><a href="#" class="link2" onclick="document.getElementById('reserve-form').submit()"><em><b>Get Quote</b></em></a></div> </div> </div> </div> </form> //----------------------------------------------------------------------------- php script //----------------------------------------------------------------------------- <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'Results from Contact form'; // Your email address. This is where the form information will be sent. $emailadd = 'm.mcdade@hotmail.co.uk'; // Where to redirect after form is processed. $url = 'http://www.mock.thetaxirank.co.uk/thankyou.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> //----------------------------------------------------------------------------- any advice will be appreciated..... thanks in advance to any kind souls !!! hello, I did my first application of mailer php today, very nice, sending 2 pdf attachments, but for record keeping, I need a copy of the mail to go to another mail, but with out the attachments, how to accomplish this please?? here the code form html: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Contact Form</title> <meta name="Generator" content="Alleycode HTML Editor"> <meta name="Description" content="Your description here..."> <meta name="Keywords" content="Your keywords here..."> </head> <body> <form method="post" action="sendmail2.php"> <p> <label>Name:</label> <br/> <input type="text" name="name" size="48" height="40"/> </p> <p> <label>Email:</label> <br/> <input type="text" name="email" size="48" height="40"/> </p> <p> <label>Child's Name:</label> <br/> <input type="text" name="childname" size="48" height="40"/> </p> <p> <label>Site:</label> <br/> <textarea name="site" rows="2" cols="45" overflow:hidden>xx.com.au</textarea> </p> <p> </p> <p> <label>Days:</label> <br/> <textarea name="days" rows="2" cols="45" overflow:hidden>Monday, Tuesday, Wednesday, Thursday, Friday</textarea> </p> <p> </p> <p> <input type="submit" value="Send"/> <a href="xx/form.html">clear</a></p> </form> </body> </html> sendmail2.php: <?php require("../phpmailer/class.phpmailer.php"); include("email.php"); $name = $_POST['name']; $childname = $_POST['childname']; $site = $_POST['site']; $days = $_POST['days']; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Host = "xxx.com"; // SMTP servers $mail->Username = "xxx"; // SMTP username $mail->Password = "xxx"; // SMTP password $mail->AddAddress($_POST['email']); $mail->From = "xxx@ax.com.au"; $mail->FromName = "xxx_online"; $mail->Subject = "Message from Alouette"; $mail->IsHTML(true); $mail->Body = $message; $mail->AddAttachment("../attachs/x.pdf"); $mail->AddAttachment("../attachs/xd.pdf"); if($mail->Send()) { echo "Message sent! Thanks ! "; print('<a href="xu/mail/form.html">Reset and Back</a>'); } ?> email.php <?php $message = ' Hello '.$name.', <br/> we have received your interest in child care services for '.$childname.' from the '.$site.' website. <br/> <br/> '.$days.' <br/> <br/> Should you have any questions regarding the information on our enrolment form or services please do not hesitate to contactkkk <br/> <br/> <br/> Regards, <br/> <a href="mailto:x@x.com.au">x@nx.com.au</a> <a href="http://www.nx.com.au" target="_new">www.neo-it.com.au</a> <br/> <strong>Childcare Management Services</strong> <br/> <br/> ' ?> i'm using a flash frontend, and i need help with a script that will take all the files in a folder (up to 6) and mail it to someone. i can do it as a zip or not. can anyone help please. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=314260.0 Ive been trying to get this email attachment to work but I think one of the headers is wrong. It wont attach the file Code: [Select] $address = "mail@site.com"; $subject = "Test HTML Message"; $hash = md5(rand().time()); $headers .= "From: yourname <you@youremail.com>\r\nReply-To: noreply@youremail.com"; $headers .= "\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"bound-{$hash}\" "; $file = "http://www.site.com/images/funny.jpg"; $attachment = chunk_split(base64_encode(file_get_contents($file))); $ext = pathinfo($file, PATHINFO_EXTENSION); $file_base = pathinfo($file, PATHINFO_BASENAME); $body = " --bound-{$hash} Content-Type: text/html Content-Transfer-Encoding: 7bit <h2>Hello from Wizecho!</h2> <p>This is the actual email you will receive with <b>HTML</b> <i>formatting.</i></p> --bound-{$hash} Content-Type: image/jpeg name=\"{$file_base}\" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: attachment {$attachment} --bound-{$hash}-- "; if(mail($address,$subject,$body,$headers)){ echo "Email Sent"; }else{ echo "Mail not sent"; } |