PHP - Php Mail Contact Form - File Attachment - Not Sending File
Hello, Can someone help me with these contact-form please, I just want to include a file (.pdf, .jpg, .png) and send the mail.
For the moment, the mail is send but not with the file included.
Here is the website http://www.coeuraprendre.art
HTML CODE :
<form id="contact-form" class="checkform" action="#" target="contact-send.php" method="post" enctype="multipart/form-data" > <div class="form-row clearfix"> <label for="name" class="req">Nom *</label> <input type="text" name="name" class="name" id="name" value="" placeholder="Name" /> </div> <div class="form-row clearfix"> <label for="email" class="req">Email *</label> <input type="text" name="email" class="email" id="email" value="" placeholder="Email"/> </div> <div class="form-row clearfix textbox"> <label for="message" class="req">Nom du projet *</label> <textarea name="message" class="message" id="message" rows="15" cols="50" placeholder="Message"></textarea> </div> <div class="form-row clearfix"> <label for="pdf" class="req">Ajoutez votre dossier d'inscription (Pdf intéractif) *</label> <input type="file" id="pdf" class="pdf" name="pdf" placeholder="Pdf" accept="image/pdf"> </div> <div id="form-note"> <div class="alert alert-error"> <strong>Error</strong>: Please check your entries! </div> </div> <div class="form-row form-submit"> <input type="submit" name="submit_form" class="submit" value="Send" /> </div> <input type="hidden" name="subject" value="From Coeur à Prendre" /> <input type="hidden" name="fields" value="name,email,message," /> <input type="hidden" name="sendto" value="info@coeuraprendre.art" /> </form> </div> <!-- Contact form -->
PHP CODE :
<?php define("WEBMASTER_EMAIL", $_POST['sendto']); if (WEBMASTER_EMAIL == '' || WEBMASTER_EMAIL == 'Testemail') { die('<div class="alert alert-confirm"> <h6><strong>The recipient email is not correct</strong></h6></div>'); } define("EMAIL_SUBJECT", $_POST['subject']); if (EMAIL_SUBJECT == '' || EMAIL_SUBJECT == 'Subject') { define("EMAIL_SUBJECT",'Contact'); } $name = stripslashes($_POST['name']); $email = trim($_POST['email']); $message = stripslashes($_POST['message']); $pdf = stripslashes($_POST['pdf']); $custom = $_POST['fields']; $custom = substr($custom, 0, -1); $custom = explode(',', $custom); $message_addition = ''; foreach ($custom as $c) { if ($c !== 'name' && $c !== 'email' && $c !== 'message' && $c !== 'pdf' && $c !== 'subject') { $message_addition .= '<b>'.$c.'</b>: '.$_POST[$c].'<br />'; } } if ($message_addition !== '') { $message = $message.'<br /><br />'.$message_addition; } $message = '<html><body>'.nl2br($message)."</body></html>"; $mail = mail(WEBMASTER_EMAIL, EMAIL_SUBJECT, $message, "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion() ."MIME-Version: 1.0\r\n" ."Content-Type: text/html; charset=utf-8"); if($mail) { echo ' <div class="alert alert-confirm"> <strong>Confirm</strong>: Your message has been sent. Thank you! </div> '; } else { echo ' <div class="alert alert-error"> <strong>Error</strong>: Your message has not been send! </div> '; } ?> Edited July 22 by cocolembo Similar TutorialsHi, I have a simple html form. <form action="mail.php" method="POST"> <p>Name</p> <input type="text" name="name"> <p>Email</p> <input type="text" name="email"> <p>Phone</p> <input type="text" name="phone"> <p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </form> I send a simple recap to e-mail through PHP. Simultaneously with this recapitulation, I would like to generate XML, which would send it in an e-mail attachment. Somehow it's not working. Would anyone help? <?php $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message"; $recipient = "**************"; $subject = "Contact Form"; $mailheader = "From: $email \r\n"; $doc = new DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $xmlRoot = $doc->createElement("xml"); $xmlRoot = $doc->appendChild($xmlRoot); $root = $doc->createElement('OrderDetails'); $root = $doc->appendChild($root); $ele1 = $doc->createElement('name'); $ele1->nodeValue=$name; $root->appendChild($ele1); $xml->saveXML(""); $mail->addStringAttachment($xml->asXML(), "xml.xml"); mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>"; ?> Thanks for any help!! Hi Guys, Please can someone shred some light on what im doing wrong. Upon form submission it takes you to the success page. It then grabs the data, emails it through to the owner as a HTML email and then attaches 2 file attachments. The issue I am having is the attachments appear BUT they will not open. Its as though the files are corrupt. Part of the form is as follows: Code: [Select] CV: <input name="fileAttach[]" type="file" class="field" /> ID: <input name="fileAttach[]" type="file" class="field" /> The PHP is as follows: (please ignore most of the HTML body content from the email, the attachment bit is at the bottom) Code: [Select] <?php // Grab Data from Form if(isset($_POST['submit'])) { // Personal Information $surname = mysql_real_escape_string($_POST['surname']); $firstname = mysql_real_escape_string($_POST['firstname']); $telephone = mysql_real_escape_string($_POST['telephone']); $mobile = mysql_real_escape_string($_POST['mobile']); $email = mysql_real_escape_string($_POST['email']); $address = mysql_real_escape_string($_POST['address']); $postcodep1 = mysql_real_escape_string($_POST['postcodep1']); $postcodep2 = mysql_real_escape_string($_POST['postcodep2']); $dob_dd = mysql_real_escape_string($_POST['dob_dd']); $dob_mm = mysql_real_escape_string($_POST['dob_mm']); $dob_yyyy = mysql_real_escape_string($_POST['dob_yyyy']); // Next of Kin $nextkinname = mysql_real_escape_string($_POST['nextkinname']); $nextkintel = mysql_real_escape_string($_POST['nextkintel']); // Availability $days_mon = mysql_real_escape_string($_POST['days_mon']); $days_tue = mysql_real_escape_string($_POST['days_tue']); $days_wed = mysql_real_escape_string($_POST['days_wed']); $days_thu = mysql_real_escape_string($_POST['days_thu']); $days_fri = mysql_real_escape_string($_POST['days_fri']); $days_sat = mysql_real_escape_string($_POST['days_sat']); $days_sun = mysql_real_escape_string($_POST['days_sun']); $availability_am = mysql_real_escape_string($_POST['availability_am']); $availability_pm = mysql_real_escape_string($_POST['availability_pm']); $availability_allday = mysql_real_escape_string($_POST['availability_allday']); $availability_requirements = mysql_real_escape_string($_POST['availability_requirements']); // Experience $experience = mysql_real_escape_string($_POST['experience']); // Rates $rate = mysql_real_escape_string($_POST['rate']); $rate_specific = mysql_real_escape_string($_POST['rate_specific']); // Employer Ref $employrefname = mysql_real_escape_string($_POST['employrefname']); $employrefcomp = mysql_real_escape_string($_POST['employrefcomp']); $employreftel = mysql_real_escape_string($_POST['employreftel']); $employrefadd = mysql_real_escape_string($_POST['employrefadd']); // Personal Ref $persrefname = mysql_real_escape_string($_POST['persrefname']); $persreftel = mysql_real_escape_string($_POST['persreftel']); $persrefadd = mysql_real_escape_string($_POST['persrefadd']); // Extra Information $allergy = mysql_real_escape_string($_POST['allergy']); $allergy_details = mysql_real_escape_string($_POST['allergy_details']); $drive = mysql_real_escape_string($_POST['drive']); $car = mysql_real_escape_string($_POST['car']); $criminal = mysql_real_escape_string($_POST['criminal']); $criminal_details = mysql_real_escape_string($_POST['criminal_details']); $howlongworkuk = mysql_real_escape_string($_POST['howlongworkuk']); $police_check = mysql_real_escape_string($_POST['police_check']); $right2work = mysql_real_escape_string($_POST['right2work']); $right2workna = mysql_real_escape_string($_POST['right2workna']); //*** Uniqid Session ***// $strSid = md5(uniqid(time())); // Email Options $subject = "XXX Job Application"; $to = "test@test.com"; $mailheader = ""; $mailheader .= "From: $email" . "\r\n"; // Applicants copy $mailheader .= "BCc: $email" . "\r\n"; $mailheader .= "MIME-Version: 1.0\n"; $mailheader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n"; $mailheader .= "This is a multi-part message in MIME format.\n"; $mailheader .= "--".$strSid."\n"; $mailheader .= "Content-type: text/html; charset=utf-8\n"; $mailheader .= "Content-Transfer-Encoding: 7bit\n\n"; // Message Content $body = '<html><head><style media="all" type="text/css">.table{background-color:#d8f0f8; cellpadding:3; cellspacing:10; border:10; width:625; bordercolor:#d8f0f8; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; padding:5;} .field{margin-left: 5px; margin-right:5px; padding:8px;}</style></head><body>'; $body .= '<table class="table"> <tr> <td colspan="5"> <h2 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.3em; margin: 0; text-transform: uppercase; padding-bottom: 10px;">Cleaner Details</h2> </td></tr> <tr> <td></td> <td width="50%" >NAME:</td> <td></td> <td width="50%" >DATE OF BIRTH:</td> <td></td> </tr> <tr class="input"> <td></td> <td bgcolor="#FFFFFF" bordercolor="#666666" class="field">' . strip_tags($_POST['firstname']) . ' ' . strip_tags($_POST['surname']) . '</td> <td></td> <td bgcolor="#FFFFFF" bordercolor="#666666" class="field">' . strip_tags($_POST['dob_dd']) . '/' . strip_tags($_POST['dob_mm']) . '/' . strip_tags($_POST['dob_yyyy']) . '</td> <td></td> </tr> <tr class="field"> <td></td> <td>ADDRESS:</td> <td></td> <td>TELEPHONE:</td> <td></td> </tr> <tr class="input"> <td></td> <td rowspan="3" bgcolor="#FFFFFF" bordercolor="#666666" class="field">' . strip_tags($_POST['address']) . ' ' . strip_tags($_POST['postcodep1']) . ' ' . strip_tags($_POST['postcodep2']) . '</td> <td></td> <td bgcolor="#FFFFFF" bordercolor="#666666" class="field">' . strip_tags($_POST['telephone']) . '</td> <td></td> </tr> <tr class="input"> <td></td> <td></td> <td>MOBILE:</td> <td></td> </tr> <tr class="input"> <td></td> <td></td> <td bgcolor="#FFFFFF" bordercolor="#666666" class="field">' . strip_tags($_POST['mobile']) . '</td> <td></td> </tr> <tr > <td></td> <td colspan=3>EMAIL:</td> <td></td> </tr> <tr > <td></td> <td colspan=3 bgcolor=#FFFFFF bordercolor=#666666 class="field">' . strip_tags($_POST['email']) . '</td> <td></td> </tr> <tr> <td colspan=5><h2 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.3em; margin: 0; text-transform: uppercase; padding-bottom: 5px; padding-top: 10px;">EMERGENCY CONTACT INFORMATION</h2></td> </tr> <tr> <td colspan=5 class="field"><hr size=1 /></td> </tr> <tr> <td></td> <td >NAME:</td> <td></td> <td >TELEPHONE:</td> <td></td> </tr> <tr > <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 class="field">' . strip_tags($_POST['nextkinname']) . '</td> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 class="field">' . strip_tags($_POST['nextkintel']) . '</td> <td></td> </tr> <tr> <td colspan=5><h2 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.3em; margin: 0; text-transform: uppercase; padding-bottom: 5px; padding-top: 10px;">EXPERIENCE</h2></td> </tr> <tr> <td colspan=5><hr size=1 /></td> </tr> <tr> <td></td> <td colspan="3" bgcolor=#FFFFFF bordercolor=#666666 class="field">' . strip_tags($_POST['experience']) . '</td> <td></td> </tr> <tr> <td></td> <td>CLEANERS RATE:</td> <td></td> </tr> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 class="field">' . strip_tags($_POST['rate']) . ' ' . strip_tags($_POST['rate_specific']) . '</td> <td></td> </tr> <tr> <td colspan=5><hr size=1 /></td> </tr> <tr> <td colspan=5><h2 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.3em; margin: 0; text-transform: uppercase; padding-bottom: 5px; padding-top: 10px;">AVAILABILITY</h2></td> </tr> <tr> <td></td> <td >WEEKDAYS:</td> <td></td> <td >SPECIFIC REQUIREMENTS:</td> <td></td> </tr> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top >Monday: ' . strip_tags($_POST['days_mon']) . '<br /> Tuesday: ' . strip_tags($_POST['days_tue']) . '<br /> Wednesday: ' . strip_tags($_POST['days_wed']) . '<br /> Thursday: ' . strip_tags($_POST['days_thu']) . '<br /> Friday: ' . strip_tags($_POST['days_fri']) . '<br /> Saturday: ' . strip_tags($_POST['days_sat']) . '<br /> Sunday: ' . strip_tags($_POST['days_sun']) . '<br /> <br /> I am available on the above days in the:<br /> <br /> Morning: ' . strip_tags($_POST['availability_am']) . '<br /> Afternoon: ' . strip_tags($_POST['availability_pm']) . '<br /> All Day: ' . strip_tags($_POST['availability_allday']) . '<br /> </td> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['availability_requirements']) . '</td> <td></td> </tr> <tr> <td colspan=5><hr size=1 /></td> </tr> <tr> <td colspan=5><h2 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.3em; margin: 0; text-transform: uppercase; padding-bottom: 5px; padding-top: 10px;">REFERENCES</h2></td> </tr> <tr> <td></td> <td><b>EMPLOYER REFERENCE</b></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td>NAME:</td> <td></td> <td>COMPANY:</td> <td></td> </tr> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['employrefname']) . '</td> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['employrefcomp']) . '</td> <td></td> </tr> <tr> <td></td> <td>ADDRESS:</td> <td></td> <td>TELEPHONE:</td> <td></td> </tr> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['employrefadd']) . '</td> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['employreftel']) . '</td> <td></td> </tr> <tr> <td></td> <td><b>PERSONAL REFERENCE</b></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td>NAME:</td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['persrefname']) . '</td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td>ADDRESS:</td> <td></td> <td>TELEPHONE:</td> <td></td> </tr> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['persrefadd']) . '</td> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top>' . strip_tags($_POST['persreftel']) . '</td> <td></td> </tr> <tr> <td colspan=5><hr size=1 /></td> </tr> <tr> <td colspan=5><h2 style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 1.3em; margin: 0; text-transform: uppercase; padding-bottom: 5px; padding-top: 10px;">OTHER INFORMATION</h2></td> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top> Police Check Complete: ' . strip_tags($_POST['police_check']) . '<br /> Criminal Convictions: ' . strip_tags($_POST['criminal']) . ' ' . strip_tags($_POST['criminal_details']) . '<br /> Right to Work: ' . strip_tags($_POST['right2work']) . '<br /> Not Applicable: ' . strip_tags($_POST['right2workna']) . '<br /> Worked in the UK: ' . strip_tags($_POST['howlongworkuk']) . '<br /> </td> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top> Allergies: ' . strip_tags($_POST['allergy']) . ' ' . strip_tags($_POST['allergy_details']) . '<br /> Drive? ' . strip_tags($_POST['drive']) . '<br /> Car? ' . strip_tags($_POST['car']) . ' </td> <td></td> </tr> <tr> <td></td> <td>SIGNED BY CLEANER:</td> <td></td> <td>DATE:</td> <td></td> </tr> <tr> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top> X </td> <td></td> <td bgcolor=#FFFFFF bordercolor=#666666 valign=top> </td> <td></td> </tr> </tr> <tr><td></td><td></td><td></td></tr> </table>'; $body .= "</body></html>"; // Upload Attachments for($i=0;$i<count($_FILES["fileAttach"]["name"]);$i++) { if($_FILES["fileAttach"]["name"][$i] != "") { $mailheader .= $body ."\n\n"; $FilesName = $_FILES["fileAttach"]["name"][$i]; $Content = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"][$i]))); $mailheader .= "--".$strSid."\n"; $mailheader .= "Content-Type: application/octet-stream; name=\"".$FilesName."\"\n"; $mailheader .= "Content-Transfer-Encoding: base64\n"; $mailheader .= "Content-Disposition: attachment; filename=\"".$FilesName."\"\n\n"; $mailheader .= $Content."\n\n"; } } // End of Email Content > Display Message echo "Thank you. Your application was submitted to us successly. We review all applications carefully and we may contact you shortly."; // Attempt to Send Email mail($to, $subject, $body, $mailheader); } else { echo "Application Failed. Unfortunatley, there was a problem with your application and it was not submitted. Please try again later or alternativley please contact us."; } ?> Any help would be much appreicated. Thanks guys! Sam Hi, I have the program which get's the results from the database and allows download of the info in .csv format. Now I want to be able to mail this file as an attachment to an email address using gmail server. I've come up with a mail program which can mail the info from database in text format... need help in modifying it to send csv attachment. Any help is greatly appreciated. Thanks in advance!! Does anyone know of a way to use PHP to create and email a HTML file? I was attempting to use the standard PHP mail function to pass a HTML string to the message variable, but mail clients have a pretty hard time rendering HTML/CSS correctly. My thought was, if I could take my HTML string and turn it into a file and attach it to a email message the user would be able to open the file in there default browser which would render without issues. Just for the record my HTML string also contains PHP variables, so it must be processes before being sent. So far my research suggests using the PEAR library for sending mail with attachments, but I am only finding literature on how to attach a file already existing on the server to an email message. I am having trouble finding a way to create a HTML file on the fly and attach it to an email message. Has anyone had a similar problem? Is there a different way to accomplish what I am attempting to do here? Can anyone tell me why this code is not working: Code: [Select] <?php $d = $_GET['p']; $u = $_GET['u']; $email_to = $_GET['e']; $email_from = "no-reply@mydomain.com"; $headers = "From: " . $email_from; $fileatt = "$d/pdffile.pdf"; $fileatt_type = "application/pdf"; $fileatt_name = "$d/pdffile.pdf"; $email_subject = "Your pdffile"; $email_message = "blablabla"; $email_message .= "Thanks for visiting.<br>"; $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"; $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 "Dear $u,<br /><br />blablabla."; } else { die("Sorry but the email could not be sent. Please go back and try again!"); } ?> This code is working properly: Code: [Select] <?php $fileatt = "dirname/myfile.pdf"; $fileatt_type = "application/pdf"; $fileatt_name = "dirname/myfile.pdf"; $email_from = "no-reply@mydomain.com"; $email_subject = "subject"; $email_message = 'Hi,<br /><br />blablabla<br>'; $email_message .= "<br /><br />Thanks for visiting.<br>"; $email_to = 'info@mydomain.com'; //$e; $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"; $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 'Hi '..'File has been sent to your e-mail address: '; echo '<br />Go check your mailbox and check your spam box.<br /><br />Thanks for your order!<br /><br />blablabla'; } else { die("Sorry but the email could not be sent. Please go back and try again!"); } ?> Maybe it is possible to add it as require_once with a function? I am lost now, strange I cannot get it at work properly with $_post / $_get... Hi, I am looking for a script which will help me to send prebuilt e-mail to people with attachments. Something like this >>> To : [ ________________ ] <--Textbox Subject : [ _____________] <-- Subject Main body : [___________________] [___________________] [___________________] [___________________] [___________________] <-- with html [ Submit ] I would like to attach 5 photos in .jpg which are hosted on server. Now everything is prebuilt except "To : " as peoples email ID will always change. When Submit is clicked, main body Data and attachment will be sent to "To :" person with SMTP and not php mail() Well I have covered till sending mail with SMTP, using PEAR PHP, but I am not able to send attachments i.e. photos. I have 2 pages, index.php - 1st page which includes form and button sendmail.php - Includes all function and main data Following is the code of sendmail.php <?php include("Mail.php"); include('Mail/mime.php'); $to = $_POST["to_textbox"]; $from = $_POST["from_textbox"]; $subject = $_POST["subject_textbox"]; $message = $_POST["content_textbox"]; $headers = "From: " . $from . "\r\n"; /* SMTP server name, port, user/passwd */ $smtpinfo["host"] = "xbc.pqr.com"; $smtpinfo["port"] = "465"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "user"; $smtpinfo["password"] = "pass"; /////////////////Attachments Section Start ////////////// $file = '/home/xyzuser/public_html/xbx.pqr.com/mail1/img/linux_logo.jpg'; $crlf = "\n"; $mime = new Mail_mime($crlf); $mime->addAttachment($file, 'image/jpeg'); //do not ever try to call these lines in reverse order $attach= $mime->get(); ///////////////Attachment Section ends //////////////// /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); /* Ok send mail */ $mail_object->send($to, $headers, $subject, $message, $attach); ?> Now problem is, it is not sending linux tux logo from "img" folder i.e. mail sent with just text from previous page's textbox. It is not handling with attachment i.e. photo, what to do ? Thanks to http://pear.php.net/manual/en/packag...me.example.php 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 guys I have created these codes below, uploadform.php Code: [Select] <html> <head> </head> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <table> <tr> <td><div align="left">Submit photo </div></td> <td><div align="left"> <input type="file" name="file" id="file" /> </div></td> </tr> <tr> <td><div align="left"></div></td> <td><div align="left"> <input type="submit" name="Submit" value="Submit" /> </div></td> </tr> </table> </form> </body> </html> upload.php Code: [Select] <?php /************************ * Upload file *************************/ if (isset($_POST['Submit'])) { //if "email" is filled out, send email /*** Upload File ***/ if($_FILES["file"]["size"] < 20000) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { //echo "Upload: " . $_FILES["file"]["name"] . "<br />"; //echo "Type: " . $_FILES["file"]["type"] . "<br />"; //echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { //$_FILES["file"]["name"] // Do nothing... } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); $url = "http://asiamodeltalent.com/php/mt/" . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } /************************ * Insert path and filename to array *************************/ $fname = $_FILES["file"]["name"]; $files = array("$fname"); /************************ * Send Message to email *************************/ $to = "iridion_us@yahoo.com"; $from = "contact@coder9.com"; $subject ="Email File"; $message = "Test email with file attached.\n"; $headers = "From: $from"; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary $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"; $message .= "--{$mime_boundary}\n"; // preparing attachments $pathupload = "http://coder9.com/php/mt/" . "upload/"; for($x=0;$x<count($files);$x++){ //$file = fopen($files[$x],"rb"); $file = fopen($url[$x], "rb"); //$data = fread($file,filesize($files[$x])); $data = fread($file, filesize($url[$x])); fclose($file); $data = chunk_split(base64_encode($data)); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $message .= "--{$mime_boundary}\n"; } // send $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<p>mail sent to $to!</p>"; } else { echo "<p>mail could not be sent!</p>"; } } ?> The problem with this codes is the file is attached but it's empty. By the way if you want to test it you need a sub directory of /upload What is the cause of this problem? Thanks in advanced. Ok, I have tried using the code from this link http://answers.yahoo.com/question/index?qid=20100927173625AAmEmiW Code: [Select] <?php // Get the name they entered in the form // We'll be naming the file this $file = $_POST['name']; // Get the email from the form $email = $_POST['email']; // We want the file to be a text file right? $ex = ".txt"; // Try to open a file named $file$ex (johndoe.txt for example) // Because this file doesn't exist yet the server creates it $write = fopen("$file$ex","w"); // Now open the file up again but this time save the email in it fwrite($write,$email); // MAKE SURE you close the file!!! fclose($write); // The folder that this script is in on the server is where the file we just made was saved // We can 'rename' it to another folder // The folder on the server we want to move it to $data = "../emails/"; // Now put it all together: This example goes out of the folder we're in and into the folder 'emails' // The new 'name' would be this now (../emails/johndoe.txt): So now the file is moved to where we want for storage rename ("$file","$data$file$ex"); // The script is done, send the user to another page (Just read the address below and you'll get it) exit; ?> unfortunately it doesn't do as i would like. I'm not sure how to get it to save a new file based on a variable on the form page or from one of the fields in the form. What i need is a way for a user to submit the form and it save the data into a uniquely named csv file. I know the code given is for text files, not csv, but that was about all i could find. If there is any help i would greatly appreciate it. I have a one-page responsive website template with a built-in contact email form whereby I would like to add an upload file attachment provision to the contact form. While I have been able to successfully add two fields (source, URL) to the built-in contact email form, with exception of adding the HTML to the form , modification to the contact email form's PHP files appears to be much more involved whereby I have been unable to find a barebones PHP code I can add to the existing PHP to make this work. I should also add that while I am well versed in HTML, CSS, and Javascript, I am not when it comes to PHP. In brief, I prefer not to replace the built-in contact form with different HTML and PHP for adding a contact form email file attachment. Any suggestions regarding this subject matter are appreciated. Since PHP is not listed under accepted file types for attachment to this post, I can provide download links to the contact email form PHP files from my iHost server for review if need be. The website address to view the HTML source code for the built-in contact form is https://www.seoauditspecialists.com. Apart from my having to add 'enctype=”multipart/form-data”' to the contact form's <form action> line of code, the HTML to add the 'file' field is provided below. Thank you ahead of time.
<div class="form-group"> So here is my code: //form.html <form action="http://localhost/lab3/index.php" method="post " > <input type="text" name="numar" value=""><br> <input type="submit" name="submitButton" value="Submit"> </form> //and in index.php ,which is in the specified folder if I write : if($_POST['numar']!="") $m=$_POST['numar']; //then I get an error saying Undefined index: numar I really read a lot about forms and saw examples , but I can't figure out what's wrong. If you have any ideas.. I can't figure out what the heck is wrong with this code. When I attempt to use it, it get an error message from my browser that the file is under maintenance or configured incorrectly. I am attempting to have a user complete a form field on my website, upload a document, and send the email to me with the file attached. <?php $subject = 'I am from '.$_POST['MID'].' '; $emailadd = 'me@domain.com'; $req = '1'; $text = "I declare that I have read and understand the Guidelines and that I comply within these guidelines. :\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 = ' '; } $file_name = $_FILES['userfile']; $new_file_name = $file_name . trim($_POST['MID']); $path= "Confirmation/" . $new_file_name; if($userfile) { if(copy($_FILES['userfile']['tmp_name'], $path)) { echo "Successful<BR/>"; echo "File Name :" . $new_file_name."<BR/>"; echo "File Size :" . $_FILES['userfile']['size']."<BR/>"; echo "File Type :" . $_FILES['userfile']['type']."<BR/>"; } else { echo "Error, file did not upload correctly!"; } mail($emailadd, $subject, $text, 'From: '.$_POST['Name'].' <'.$_POST['Email'].'>'); header("Location: compliance/confirmation.html"); ?> What am I doing wrong? Thanks! Hello, I'm new to PHP but i am quite good with javascript programming etc so i'm just getting to terms with using PHP. I've made a contact form with an IF statement that will display confirmation within my page upon post. (I'm not even sure if this logic is right however). The form seems to submit but doesn't show the confirmation message and doesn't send an email to my webserver. Code: [Select] <body> <div id="outer"> <div id="topbar"> </div> <div id="topback"> <img src="images/logo.png" class="logo" /> <a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('hemcurrent','','images/homecurrent.png',1)"><img src="images/home.png" class="logo hem" name="hemcurrent" /></a> <a href="Tjanster.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('tjanstercurrent','','images/tjanstercurrent.png',1)"><img src="images/tjanster.png" class="logo links" name="tjanstercurrent" /></a> <a href="OmOss.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('omosscurrent','','images/omosscurrent.png',1)"><img src="images/omoss.png" class="logo links" name="omosscurrent" /></a> <a href="Referenser.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('referensercurrent','','images/referensercurrent.png',1)"><img src="images/referenser.png" class="logo links" name="referensercurrent" /></a> <a href="KontaktaOss.html"><img src="images/kontaktaosscurrent.png" class="logo links" /></a> </div> <div id="maincontent"> <h1>Nordströms HRK AB - </h1> <h2 class="kontaktaoss"> KONTAKTA OSS</h2> <?php if ($_POST["email"]<>'') { $ToEmail = 'michel@hissorulltrappskonsulter.se'; $EmailSubject = 'Webform Hissorulltrapp'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"].""; $MESSAGE_BODY .= "Email: ".$_POST["email"].""; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> Your message has been sent <?php } else { ?> <form name="form" id="form" action="KontaktaOss.php" method="post"> <select name="sDepartment" onchange="MM_jumpMenu('parent',this,0)" class="selectDepartment"> <option>Hiss och rulltrappstjänster</option> <option>Teknisk support</option> </select> <input type="text" name="subject" id="name" class="txtDepartment" /> <textarea name="tComments" id="comment" class="txtComments"></textarea> <input type="text" name="tEmail" id="email" class="txtEmail" /> <input type="image" src="images/submit.png" class="bSubmit" value="send" /> <input type="image" src="images/reset.png" class="bReset" /> </form> <?php }; ?> <p class="kontaktaossdetails"><b>Information:</b><br /> Stationsvägen 4C<br /> Täby 187 30 <br /> Telefon: 0702698981<br /> bjorn@hissotrulltrappskonsulter.se<br /> michel@hissorulltrappskonsulter.se<br /> <b>Teknisk Support:</b><br /> joel@hissorulltrappskonsulter.se</p> </div> <div id="tagline"><img class="quote1" src="images/quote1.png" /> <div id="elem0" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem1" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem2" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem3" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem4" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem5" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem6" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem7" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem8" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <div id="elem9" class="toBeFaded tagline"><p> Björn har under sin anställning utvecklat en gedigen kompetens inom sitt arbetsområde. Han har i sin roll visat stort engagemang för sina arbetsuppgifter.. -<em> Harry Plogbäck, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem10" class="toBeFaded tagline"><p>Behovet av kvalitetskontroller erinrar sig från värdet av en kontrollverksamhet jämtemot de som utför reparationer och service. Det skapar även möjligheten... -<em> Björn Anderson, Teknisk förvaltningschef - AB Storstockholms Lokaltrafik</em></p></div> <div id="elem11" class="toBeFaded tagline"><p>Angående utförandet av arton kvalitetskontroller samt rådgivning för PUB, Atrium Fastigheter. “Rulltrappskonsulterna har hjälpt mig att få fram en rättvis bild... -<em> Stefan Fransson, Teknisk förvaltare för PUB, Atrium Fastigheter AB</em></p></div> <img class="quote2" src="images/rightquote.png" /> <img src="images/btnLogin.png" class="btnlogin" /> </div> <div id="copyright"> <ul id="nav"> <li>LANGUAGES: </li> <li><a href="#">ENGLISH</a></li> <li><a href="#">SWEDISH</a></li> <li><a href="#">HELP</a></li> <li>COPYRIGHT BY NORDSTRÖMS HRK AB</li> </ul> </div> <div id="mac"> <div id="macscreen"> <iframe width="336" height="216" src="http://www.youtube.com/embed/AhfK9_ZlRXQ?hl=en&fs=1&rel=0&autoplay=1&autohide=1&showinfo=0&controls=0&loop=1" frameborder="0"></iframe> </div> </div> </div> </body> Just looking for some advice really, i'm sure it's something very simple! Thank you. Please help: I'm trying to figure out what is going on with a custom made PHP contact form on my company's multiple websites. Check it out he www.TacticalSolar.com This custom form was made by a former employee and USUALLY works great. Validation, spam checking, database connection, etc. But I've discovered a bug. The form does not always actually send the data to us when it says it does! This problem almost always happens in Internet Explorer and Safari browsers. But sometimes that data shows up. This does not effect Firefox or Chrome. I've been looking everywhere, but no idea what is causing this. Thoughts? Ideas? I'm no PHP coder so even obvious places to look are welcome. system: vista ultimate sp2 IIS 7 server installed and running PHP 5 fastCGI im not sure if this is within the purview of the forum but you all seem like smart people with an expertise in this area. i have a web site http://penumbraproductions.dyndns-remote.com/ . it is hosted locally on my desktop using the above mentioned IIS7 server options using dyndns to list the url cause my ISP has DHCP without static ip's for non-business accounts that has a contact form... form mail. i've tried numerous php codes to get it to send mail to my email account but none of them are working my IIS smtp setting a email to: archaismic@gmail.com smtp server: smtp.gmail.com port number: 465 using login credentials i've also tried to configuring the smtp options in IIS to dump the mail to a folder on my computer which also did not work attached is the feedback.php file im currently working with minus the captcha private key and the code for the form i'm using is: Code: [Select] <form action="feedback.php" method="post"> <table border="0" cellpadding="8" cellspacing="8"> <tr><td><label for="tswname">Name</label>:</td><td><input type="text" name="fullname" id="tswname" size="25" /></td></tr> <tr><td><label for="tswemail">Email address</label>:</td><td><input type="text" id="tswemail" name="email" size="25" /></td></tr> <tr> <td colspan="2"> <label for="tswcomments">Comments</label><br /> <textarea rows="15" cols="45" name="comments" id="tswcomments"></textarea> </td> </tr> <tr> <td align="center" colspan="2"> <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LcYjcASAAAAAH1NwZ0IH_TUO4XDANZqWu3Ei9yh"></script> <noscript> <iframe src="http://api.recaptcha.net/noscript?k=6LcYjcASAAAAAH1NwZ0IH_TUO4XDANZqWu3Ei9yh" height="300" width="500" frameborder="0" title="CAPTCHA test"></iframe> <br /> <label for="tswcaptcha">Copy and paste the code provided in above box he </label><br /> <textarea name="recaptcha_challenge_field" id="tswcaptcha" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge" /> </noscript> </td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="Send Feedback" /> </td> </tr> </table> </form> Hi, i have a script problem as I am a graphic designer with zero php knowledge. I have a contact script that sends emails but they are blank. Meaning all text fields are not sending. If you could correct this for me thanks in advance. Here is my hacked up script that sends email with empty fields: Basically what I am needing is when a visitor comes to my site and request info on a product, the form sends the product id or name.
I have the site set up like product.php?Item=26 and the item number changes based on the product. The page items are being populated with info stored in the mysql databse.
I need the email being sent to say something like
Visitors Name has requested info on Item 26 Name - Visitors Name Email - email@me.com Phone - 123-456-7890 Company - Visitors Company Item info requested for Here is the products name URL to product page Basically the "item info" is being pulled from the database. I have asked on different forums and I cannot get a good answer that I can use to make this happen. I might not be explaining it right. Page the form is on is (and all other new-product.php pages) http://www.packagingequipment4sale.com/new-product.php?Item=26Any help would be greatly appreciated I've been ALL over the internet trying to find complete step by step guides on getting php to work for my contact form and I can't find anything. Or at least nothing that makes sense to me. I know nothing about PHP, I'm more of a designer/html/css person. PHP is completely foreign to me and very hard to understand. I have downloaded PHPMailer but I have no idea what I'm supposed to do with it or how to really configure it. I really need help in that area. This contact form is the last thing I need before I can put my redesign of my website up.
Hi I am very new to PHP. I'm wanting a feedback form on my website where the form is sent via SMTP rather than sendmail. I have checked that php is working by doing this code: Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', True); $path = '/home/****/php'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); echo("<p>Sending PEAR Mail.php...</p>"); require('Mail.php'); $from = "Info <info@***.co.uk>"; $to = "Info <info@***.co.uk>"; $subject = "Hi - Test message!"; $body = "Hi,\n\nHow are you?"; $host = "mail.***.co.uk"; $username = "info@***.co.uk"; $password = "***"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> This works fine. I then created a form in my contact page: Code: [Select] <form name="feedbackform" action="form-mailer2.php" method="post"> <input type="hidden" name="Required" value="Name,Comments"> <p>Name: <input name="Name" size="30"> <span class="formsmall">required</span></p> <p>E-mail: <input name="Email" size="30"> <span class="formsmall">optional</span></p> <p>Feedback/Comments:</p> <p><textarea name="Comments" rows="5" cols="40"></textarea></p> <p><input type="submit" value="Submit" name="submitform"><input type="reset" value="Reset" name="reset"></p> </form> I then used the code based on the php initial example and the code file that would get the form details from the contact page and send to the email address via smtp. I have left the validations in - although if these are no good please feel free to tell me! I will want to put a captcha in but need to look into that yet. Anyway, the code I have created is now this (which is saved in the file form-mailer2.php): Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', True); $path = '/home/****/php'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); echo("<p>Sending PEAR Mail.php...</p>"); require('Mail.php'); $mailfrom = "info@***.co.uk"; $mailTo = "info@***.co.uk"; $mailSubject = "Web Feedback"; $mailHost = "mail.***.co.uk"; $mailPort = "25"; $mailAuth = "true"; $mailPassword = "****"; // Get the form fields. $name = $_POST['Name']; $email = $_POST['Email']; $comments = $_POST['Comments']; $reqFields = $_POST['Required']; // I find including the time/date useful for record-keeping. // Note that it is the web server's time/date, not yours // or the sender's. $date = date("l jS F Y, g:i A"); // A simple yet reasonably effective email address validator. if ((!ereg(".+\@.+\..+", $email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $email))) { $errorMessages .= "<li>Invalid email address: $email</li>"; } // Make sure required fields are filled in. $checkFields = explode(",",$reqFields); while(list($theField) = each($checkFields)) { if(!$$checkFields[$theField]) { $errorMessages .= "<li>Missing $checkFields[$theField]</li>"; } } // If there are errors, display them and a back button. if($errorMessages) { ?> <p>Errors were found on the form.</p> <ul> <?php echo $errorMessages; ?> </ul> <p><input type="button" value="Back" onClick="history.back()"></p> <?php } // No errors, send the message and print out success message. else { // Build the email. $body = " Name: $Name Email: $Email Phone: $Phone ----- Comments ----- $Comments -------------------- $headers["From"] = $mailTo; $headers["To"] = $mailTo; $headers["Subject"] = $mailSubject; $params["host"] = $mailHost; $params["port"] = $mailPort; $params["auth"] = $mailAuth; $params["username"] = $mailTo; $params["password"] = $mailPassword; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($mailTo, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } // I would rather redirect to a different thank you page but both of next options don't work when taking out: echo("<p>Message successfully sent!</p>"); //RedirectToURL("thank-you.php"); or header(Location: "thank-you.php" ); ?> Depending on what I change about I either get: The website cannot display the page or a list of undefinable variables. If anyone is able to understand the php and notice where the problem lies I would be so grateful. Thank you. I really need some help. I am very new to PHP and I've been stuck for a couple of days. I created a contact form and everything seems to be working correctly, except the mail is showing it's sent, but I never receive an email in my Inbox or Spam folder. Can someone please review my code? Here is the PHP: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varpositionErr = ""; $varfname = $varlname = $varemail = $varphone = $varposition = $success = ""; //FORM SUBMITTED WITH POST METHOD if ($_SERVER["REQUEST_METHOD"] == "POST") { //VALIDATE FIRST NAME if (empty($_POST["varfname"])) { $varfnameErr = "First Name is required"; } else { $varfname = test_input($_POST["varfname"]); // MAKE SURE FIRST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varfname)) { $varfnameErr = "Only letters and white space are allowed"; } } //VALIDATE LAST NAME if (empty($_POST["varlname"])) { $varlnameErr = "Last Name is required"; } else { $varlname = test_input($_POST["varlname"]); // MAKE SURE LAST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varlname)) { $varlnameErr = "Only letters and white space are allowed"; } } //VALIDATE EMAIL ADDRESS if (empty($_POST["varemail"])) { $varemailErr = "Email Address is required"; } else { $varemail = test_input($_POST["varemail"]); // MAKE SURE EMAIL ADDRESS IS FORMATTED CORRECTLY if (!filter_var($varemail, FILTER_VALIDATE_EMAIL)) { $varemailErr = "Invalid email address format"; } } //VALIDATE PHONE NUMBER if (empty($_POST["varphone"])) { $varphoneErr = "Phone number is required"; } else { $varphone = test_input($_POST["varphone"]); // MAKE SURE PHONE NUMBER IS IN CORRECT FORMAT if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$varphone)) { $varphoneErr = "Invalid telephone format"; } } //VALIDATE POSITION if (empty($_POST["varposition"])) { $varpositionErr = "Position is required"; } else { $varposition = test_input($_POST["varposition"]); } //IF ALL DATA IS CORRECT if ($varfnameErr == '' and $varlnameErr == '' and $varemailErr == '' and $varphoneErr == '' and $varpositionErr == '') { $message_body = ''; unset($_POST['submit']); //THIS IS JUST FOR TESTING PURPOSES $message_body = $varfname; //foreach ($_POST as $key => $value) { // $message_body .= "$key: $value\n"; //} $to = 'mygmail@gmail.com'; $subject = 'Volunteer Form Submission'; $message = wordwrap($message_body, 70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: " . $varemail . "\r\n"; $subject = 'Volunteer Form Submission'; $to = 'mygmail@gmail.com'; $result = mail($to, $subject, $message, $headers); //THIS RETURNS "1" print $result; //IF ALL DATA IS CORRECT MAKE SURE EMAIL WAS SENT if (mail($to, $subject, $message, $headers)) { $success = "Message sent. Thank you contacting us! We will reply as soon as possible."; $varfname = $varlname = $varemail = $varphone = $varposition = ""; } else { $success = "Something went wrong!"; } } } //STRIP UNWANTED CHARACTERS FROM VARIABLES function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
Here is the HTML: <div class="row regformrow"> <div class="coffee-span-12 regformcolumn"> <div class="subgrid regformsubgrid"> <div class="row regformsubgridheaderrow"> <div class="coffee-span-12 regformsubgridheadercolumn"> <h4 class="regformsubgridheadertitle">Volunteer Form</h4> </div> </div> <div class="row regformsubgridrow"> <form class="form-container regformsubgridformcontainer" action=<?= $_SERVER['PHP_SELF']; ?> method="post"> <div class="coffee-span-4 coffee-972-span-6 coffee-458-span-12 regformsubgridcolumn1"> <div class="container regformsubgridcontainer1"> <label class="label form-label-all"><span style="font-style:italic;color:#FF5454;">* Required Fields</span></label></br> <div class="formfieldgroup"> <input class="fname" name="varfname" type="text" tabindex="1" placeholder="First Name" value="<?= $varfname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varfnameErr ?></span> </div> <div class="formfieldgroup"> <input class="lname" name="varlname" type="text" tabindex="2" placeholder="Last Name" value="<?= $varlname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varlnameErr ?></span> </div> <div class="formfieldgroup"> <input class="email" name="varemail" type="text" tabindex="2" placeholder="Email Address" value="<?= $varemail; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varemailErr ?></span> </div> <div class="formfieldgroup"> <input class="phone" name="varphone" type="text" tabindex="2" placeholder="Telephone Number" value="<?= $varphone; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varphoneErr ?></span> </div> <div class="formfieldgroup"> <select class="select selectbox" name="varposition" id="varposition" tabindex="5"><option value="">Select one...</option><option value="Chaperone">Chaperone</option><option value="Class Monitor">Class Monitor</option><option value="Parking Attendant">Parking Attendant</option><option value="Party Coordinator">Party Coordinator</option><option value="Teacher Aid">Teacher Aid</option></select><span class="requiredfield"> *</span> <span class="form-error"><?= $varpositionErr ?></span> </div> <div class="formfieldgroup"> <input class="test" name="test" type="text" tabindex="6" placeholder="If you are human, leave this field blank" value=""> </div> <div class="formfieldgroup"> <button type="submit" class="button-submit-1" name="submit" tabindex="7" data-submit="...Sendng">Submit</button> </div> <div class="formfieldgroup"> <div class="success"><?= $success; ?></div> </div> </div> </div> </form> </div> </div> </div> </div> Edited February 20, 2020 by mike3075 |