PHP - Generating Xml From An Html Form And Sending An Attachment To E-mail
Hi, 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!! Similar TutorialsHello, 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 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 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? Hi guys, I'm trying to write a script that generates a multipart plaintext/HTML email with a pdf attachment. After much research and trial & error, I seem to have reached a wall. At the moment, I am testing in gmail, hotmail and Outlook 2003. Gmail displays the HTML alternative of the message and attaches the pdf document, while hotmail & Outlook only attach the pdf without displaying either of the message alternatives. Here is the code: // Error display ini_set ('display_errors', 1); error_reporting (E_ALL | E_STRICT); // Setting a timestamp date_default_timezone_set('Australia/Perth'); $timestamp = date("d/m/y H:i:s", time()); // Create a boundary string. It must be unique, so we use the MD5 algorithm to generate a random hash $random_hash = md5(time()); // Read the attachment file contents into a string, encode it with MIME base64 & split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents("success.pdf"))); // Create the Plain text message to be sent in the email body $content_text = "Hello, World!! \nIs this a Plain Text alternative?"; // Create the HTML message to be sent in the email body $content_html = "<html><body><h1>Hello, World!!</h1><p>This is <b>HTML</b> formatting.</p></body></html>"; // Sending the email $to = "$email"; $subject = "Test5-3.php :: $timestamp"; $headers = "From: The Company <webmaster@example.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$random_hash\"\n"; $headers .= "--$random_hash\n"; $headers .= "Content-Type: application/pdf\n"; $headers .= "Content-Transfer-Encoding: base64\n"; $headers .= "Content-Disposition: attachment; filename=\"success.pdf\"\n\n"; $headers .= "$attachment\n"; $message = "Content-Type: multipart/alternative; boundary=\"$random_hash\"\n"; $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: 7bit\n"; $message .= "$content_text\n"; $message .= "--$random_hash\n"; $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: 7bit\n"; $message .= "$content_html\n"; $message .= "--$random_hash--"; // Send the data in an email $mail_sent = @mail ($to, $subject, $message, $headers, "[email]-froot@clarebyrnedesign.com.au[/email]"); (That's not the full script, but it is the relevant part of it. The full script is attached.) Other variations of this code I have tried out include: - surrounding all the variables with ". .", eg: $headers .= "--".$random_hash."\n"; - sending the entire function as headers, instead of splitting it into message and headers, eg: $headers = "From: The Company <webmaster@example.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$random_hash\"\n"; $headers .= "--$random_hash\n"; $headers .= "Content-Type: application/pdf\n"; $headers .= "Content-Transfer-Encoding: base64\n"; $headers .= "Content-Disposition: attachment; filename=\"success.pdf\"\n\n"; $headers .= "$attachment\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$random_hash\"\n"; $headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $headers .= "Content-Transfer-Encoding: 7bit\n"; $headers .= "$content_text\n"; $headers .= "--$random_hash\n"; $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; $headers .= "Content-Transfer-Encoding: 7bit\n"; $headers .= "$content_html\n"; $headers .= "--$random_hash--"; Does anyone know why I would be having this problem? It seems that nothing I've tried will work!! Thanks 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 Guys, I've got a contact form set up, where the user can submit their design they have created on the site. The file uploads to a directory titled "Uploads" and the idea would then be set up a link within an HTML style E-Mail, I've had a look at MIME-TYPE on the php.net manual. I've got the form to work to an extent, however the PHP variables are not being echo'ed out and the E-Mail looks like this : Quote <html> <body> <b>New Design by $name </b> <p>Contact Details...</p> Telephone : $telephone<br /> E-Mail : $email<br /> Design : <a href=http://wwww.mysite.co.uk/Mail%20Test/uploads/$upfile>$upfile</a> </body> </html> New EasyFluid Design Added My Code is as follows : Code: [Select] <?php $to = ""; // User E-Mail $subject = "New Design Added"; // The Subject //$target_path = "uploads/"; // $target_path = $target_path . basename( $_FILES['design']['name']); //if(move_uploaded_file($_FILES['design']['tmp_name'], $target_path)) { //} extract($_POST); $from = "From: {$_POST['name']} <{$_POST['email']}>"; // From (the field named "name" and the email field named "email" //Handle the Image $upfile = 'uploads/' .$_FILES['design']['name'] ; if (is_uploaded_file($_FILES['design']['tmp_name'])) { if (!move_uploaded_file($_FILES['design']['tmp_name'], $upfile)) { echo 'Problem : Could not move file to destination directory'; exit; } } $message = ' <html> <body> <b>New Design by $name </b> <p>Contact Details...</p> Telephone : $telephone<br /> E-Mail : $email<br /> Design : <a href=http://wwww.mysite.co.uk/Mail%20Test/uploads/$upfile>$upfile</a> </body> </html> '; // To send HTML mail, the Content-type header must be set $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to, $from, $subject, $message, $headers); // HTML Style E-Mail ?> Any help on how I can correct this would be much appreciated. Thanks I have a notification system that notifies users of new comments, inside the email I have images, some of the logo, some of different people, everything shows up fine on my computer (yahoo email), however in the iPhones email application no images show up, there are just the blue squares with the question marks in them. I'm not sure what I'm missing. Code: [Select] $from = "Kithell <notifications@kithell.com>"; $headers = "From:" . $from ."\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $subject = name($from_id, 'fl').$action; $message = '<html><body> <style>@charset "utf-8"; /* CSS Document */ .e-container { background-color: #FFF;position: relative;width: 90%;min-height:1px;margin-right: auto;margin-left: auto; } .e-container .e-m-header { padding: 2px; background-image: url(http://www.kithell.com/assets/tall-grey-header.png); background-repeat: repeat-x; border: 1px solid #CCC; background-position: bottom; display: block; text-align: center; } .e-container p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #666; vertical-align: text-top; display: inline-block; } .e-container .e-usr-photo { display: inline-block; margin: 10px; float: left; background-color: #F4F4F4; } .e-container p a { font-weight: bold; color: #3F60A3; text-decoration: underline; padding: 0px; float: left; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px; } .e-container .e-quotes { font-size: 20px; font-weight: bold; color: #999; font-family: Tahoma, Geneva, sans-serif; display: block; padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 75px; margin-top:10px; } .e-container .e-message { font-size: 13px; color: #333; padding: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 10px; clear: none; display: inline; }</style> <div class="e-container"><div class="e-m-header"><img src="http://www.kithell.com/assets/kithell-logo.png" /></div><img class="e-usr-photo" src="http://www.kithell.com/'.photo($from_id, 55).'" /><br /><p><a target="_blank" href="http://www.kithell.com/#/profile&id='.$from_id.'">'.name($from_id, "fl").' </a> '.$action.'<div class="e-quotes">"<p class="e-message">'.nl2br(htmlentities(stripslashes($message))).'</p>"</div></p></div></body></html>'; mail($to,$subject,$message,$headers); Hi Everyone, I am trying to send email with the mail() function as per instructions at: http://php.net/manual/en/function.mail.php without success. The mail sends but when it arrives it doesn't render properly, I see all of the html tags with the data that's sent. My code is below: Code: [Select] <?php function processFormData($array, $form) { $errors = NULL; $message = NULL; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers = "From: <chuck@deneb-consulting.com>" . "\r\n"; $headers .="Cc: <tinwakr@bell.net>" . "\r\n"; $headers .= "Reply-to: <chuck@deneb-consulting.com>" . "\r\n"; $headers .= "X-Mailer: PHP/" .phpversion() . "\r\n"; foreach($array as $key => $value) { //if any of the form values are empty catch them and add to error array if(empty($value) && $key != 'submit') { //build error list $errors .= '"' . str_replace('_', ' ', $key) . '" is a required field!<br />'; } else if(!empty($value) && $key != 'submit') { //capture values and insert them into a session variable $_SESSION[$key] = $value; } } if(empty($errors)) { $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\r\n"; $message .= '<html><head><title>' . $form .'</title></head>' . "\r\n" . '<body><table border="1">' . "\r\n"; foreach($array as $key => $value) { //regular expression check for phone number if(str_replace('_', ' ', $key) == 'Phone Number' && !preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $value)) { return 'Please enter a valid phone number!'; } //regular expression check for email if(str_replace('_', ' ', $key) == 'Email Address' && !preg_match("/^[A-Z0-9._%-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i", $value)) { return 'Please enter a valid email address!'; } if($key != 'submit') { $message .= '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>' . "\r\n"; } } $message .= '</table></body></html>' . "\r\n"; mail("chuck@deneb-consulting.com", $form, str_replace("_", " ", $message), $headers); return 'Thank you, someone will contact you shortly.'; } else { return $errors; } } ?> Thanks in advance for all replies, Chuck Okay, below is my mailer for a contact form i created. On one site it works fine. I even have it sending to several addresses from the othersite. However this site it doesnt want to work. PHP5 and mail() function is active. <?php $Name = Trim(stripslashes($_POST['fullname'])); $EmailFrom = Trim(stripslashes($_POST['email'])); $EmailTo = "james@jd-creations.co.uk"; $Subject = Trim(stripslashes($_POST['subject'])); $answer = Trim(stripslashes($_POST['answer'])); $Comments = Trim(stripslashes($_POST['message'])); $Subject = "The Reason - Contact Us"; // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($answer)!=="20") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Comments)=="") $validationOK=false; if (Trim($Subject)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=../contact/error2.php\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Email: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "Comments: "; $Body .= $Comments; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=../contact/sent.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=../contact/error.php\">"; } ?> now i know it is wroking because it takes me to the sent.php page. not error.php i think it worked once. now not at all. OK so I am trying to send a email with the results of a submitted form to a specified email address. However when the email is received the data is not displayed rather the variable names are. See code and resulting email address below. // custom route code //Send Email // recipients $to = '********@*********.com'; // subject $subject = 'Jobs Form Submission!'; // message $message = ' <html> <head> <title>Jobs Form Submission!</title> </head> <body> Title: $job_title<br /> Company: $job_company<br /> Introduction: $job_intro <br /> Description: $job_description <br /> Required Qualifications: $job_req_qualifi <br /> Preferred Qualifications: $job_preerred_qualifi <br /> Contact Name: $job_contact_name <br /> Contact Company: $job_contact_company <br /> Contact E-mail: $job_contact_email <br /> Contact Phone: $job_contact_phone <br /> Contact Fax: $job_contact_fax <br /> </body> </html> '; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: ******** <********@*********.com>' . "\r\n"; $headers .= 'From: $job_contact_email <$job_contact_email>' . "\r\n"; $headers .= 'Cc:' . "\r\n"; $headers .= 'Bcc:' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); Email Address: Quote MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 To: ********<******@**********.com> From: $job_contact_email <$job_contact_email@***********.com> Cc: <html> <head> <title>Jobs Form Submission!</title> </head> <body> Title: $job_title<br /> Company: $job_company<br /> Introduction: $job_intro <br /> Description: $job_description <br /> Required Qualifications: $job_req_qualifi <br /> Preferred Qualifications: $job_preerred_qualifi <br /> Contact Name: $job_contact_name <br /> Contact Company: $job_contact_company <br /> Contact E-mail: $job_contact_email <br /> Contact Phone: $job_contact_phone <br /> Contact Fax: $job_contact_fax <br /> </body> </html> Any pointers would be great. Thanks in advance 0_o 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] From our website we are connecting to GMAIL to send our emails through SMTP. For some reason it is not sending the emails to the CC or BCC email address event though GMAIL shows it was included in the email. Am I missing something in the below code? Code: [Select] $currentTime = time(); $emailTo = "redbrad0@domain.com"; $emailCC = "brad@domain.com"; $emailBCC = "events@domain.com"; $emailSubject = "TEST Email at (" . $currentTime . ")"; $emailBody = "This is the body of the email"; $headers = array(); if (!empty($emailTo)) $headers['TO'] = $emailTo; if (!empty($emailCC)) $headers['CC'] = $emailCC; if (!empty($emailBCC)) $headers['BCC'] = $emailBCC; if (!empty($emailSubject)) $headers['Subject'] = $emailSubject; $headers['From'] = "events@domain.com"; $mime = new Mail_mime("\n"); $mime->setTXTBody($emailBody); $body = $mime->get(); $headers = $mime->headers($headers); $mail = Mail::factory('smtp', array ('host' => 'ssl://smtp.gmail.com', 'auth' => true, 'port' => 465, 'username' => 'events@domain.com', 'password' => 'thepasswordhere')); try { $result = $mail->send($emailTo, $headers, $emailBody); } catch (TixException $ex) { echo "<font color=red>Error:" . $ex->getCode() . "</font><br>"; } echo "Emailed at (" . $currentTime . ")<br>"; die; 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'm setting up a newsletter thing for my website. I have a newsletter table in MySQL: Quote +----------------+------+--------+ | email | mens | womens | +----------------+------+--------+ | test2@test.com | 1 | 1 | | test1@test.com | 1 | 0 | +----------------+------+--------+ I am using a HTML form and this PHP code I learn't from the manual, which sends out e-mail's. PHP: if ($_POST['newsletter'] == 'Mens') { $to = ''; $subject = $_POST['subject']; $body = $_POST['body']; $header = 'From: Me Someone <me@someone.com>'; mail($to, $subject, $body, $header); } What I want to do with the above code is send out an e-mail to all the e-mails in my MySQL database that are tagged '1' under mens. How would I go about doing this? I'm guessing I will have to use a MySQL query in the $to = ''; that goes something like this: $to = '$query (select from `newsletters` where `email` = 1'); ? Hello to all out there! this is my first post,so my question may sound a bit simple. :] I am studying PHP and MySQL and I tried to make a mailing form based on a mysql database. My problem occured when I tried to use the PEAR mail object. Here is my code: // THE INCLUDED FILES require_once ("attach_file.php" ); require_once ("Mail.php" ); require_once ("Mail\mime.php" ); //THE VARIABLES TAKEN FROM THE HTML FORM OR JUST CREATED FOR THE CONSTRUCTION OF THE EMAIL $my_email = "something@gmail.com"; $email_subject = mysql_real_escape_string(trim( $_POST['email_subject']),$server_connect ); $email_body = mysql_real_escape_string(trim( $_POST['email_body'] ),$server_connect ); $attached_file = $destination ; // the $destination variable comes from the copy() function in attach_file.php $username = "the_username@gmail.com"; $password = "the_password"; $host = "smtp.gmail.com"; $attach = new Mail_mime(); $attach -> addAttachment($attached_file); $email_body = $attach->get(); $extraheaders = array('from'=>$my_email,'to'=>$email_etaireias,'subject'=>$email_subject,'Bcc'=>$email_etaireias); $headers = $attach -> $headers($extraheaders); // HERE GIVES ME AN ERROR!!! -->Fatal error: Method name must be a string $smtp_info = array('host'=>$host,'auth'=>TRUE,'username'=>$username,'password'=>$password); $smtp = Mail::factory('smtp',$smtp_info); //loop through every single line of the database until there are no more lines with data //and store each line in 3 different variables that i can use while ( $row = mysql_fetch_array($result) ) { $onoma_etaireias = $row['onoma_etaireias']; $email_etaireias = $row['email_etaireias']; $website_etaireias = $row['website_etaireias']; } //construct the mail function . The @ is supressing the errors created .remove it and they will be shown. $mail = @$smtp->send($email_etaireias,$headers,$email_body); As i searched here and there for a solution, i found that it has something to do with the way the mail-mime object creates the body of the email . I also tried to find a solution from the PEAR documentation. do i create the headers someway wrong????? i have wrote following code for send email with attachment but it is not working. Please review it and tell me the problem in code. <?php // request variables // important $from = $_REQUEST["from"]; $emaila = $_REQUEST["emaila"]; $filea = $_REQUEST["filea"]; $to = "rizwanullahtahir@gmail.com"; $candidatename = $_POST['candidate-name']; $guardianname = $_POST['guardian-name']; $relationwithguardian = $_POST['relation-with-guardian']; $candidateemail = $_POST['candidate-email']; $guardianemail = $_POST['guardian-email']; $dateofbirth = $_POST['birthday']; $ageofCandidate = $_POST['Age']; $candidatesex = $_POST['sex']; $phone = $_POST['phone']; $skypeusername = $_POST['skype-username']; $whatsapp = $_POST['Whatsapp-username']; $permanentaddress = $_POST['permanent-address']; $mailingaddress = $_POST['mailing-address']; $country = $_POST['country']; $timezone = $_POST['timezone_offset']; $stateprovince = $_POST['State/Province']; $city = $_POST['City']; $zipcode = $_POST['zip-code']; $moftech = $_POST['Medium-Of-Teaching']; $classenroll = $_POST['Class-Enrollment']; $paymentmethod = $_POST['Payment-Method']; $fileattachment = $_FILES['attachment']['name']; $admitdate = $_POST['Admission-Form-Submission-Date']; if ($filea) { function mail_attachment ($email_from , $to, $subject, $message, $attachment){ $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start = strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $email_from = $from . '$emaila'; // Who the email is from $subject = "New Applicant Documents"; $email_subject = $subject; // The Subject of the email $email_txt = $message; // Message that the email has in it $email_to = $to; // Who the email is to $headers = "From: . '$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $msg_txt='\n\n You have recieved a new attachment message from $from' . '\n\n Candidate Name: . $candidatename <br/>' . '\n\n Guardian Name: . $guardianname<br/>' . '\n\n Relation With Candidate: . $relationwithguardian<br/>' . '\n\n Candidate Email: . $candidateemail <br/>' . '\n\n Guardian Email: . $guardianemail<br/>' . '\n\n Date of Birth: . $dateofbirth <br/>' . '\n\n Candidate Age At the Time of Admisssion: . $ageofCandidate<br/>' . '\n\n Candidate Sex: . $candidatesex<br/>' . '\n\n Phone: . $phone <br/>' . '\n\n Skype Username: . $skypeusername <br/>' . ' '\n\n Whatsapp: . $whatsapp <br/>' . '\n\n Permanent Address: . $permanentaddress<br/>' . '\n\n Mailing Address: . $mailingaddress<br/>' . '\n\n Country: . $country<br/>' . '\n\n State/Province: . $stateprovince<br/>' . '\n\n City: . $city<br/>' . '\n\n Time-Zone: . $timezone<br/>' . '\n\n Zip Code: . $zipcode<br/>' . '\n\n Medium Of Teaching: . $moftech<br/>' . ' \n\n Class Inwhich Want to Enroll: . $classenroll<br/>' . '\n\n Payment Method: . $paymentmethod<br/>' . '\n\n Date Of Application submission: . $admitdate <br/>' $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_txt = "$msg_txt"; $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_txt . "\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 "File Sent Successfully."; unlink($attachment); // delete a file after attachment sent. }else { die("Sorry but the email could not be sent. Please go back and try again!"); } } move_uploaded_file($_FILES["filea"]["tmp_name"], 'temp/'.basename($_FILES['filea']['name'])); mail_attachment("$from", "$to", "$subject", "$message", ("temp/".$_FILES["filea"]["name"])); } ?>
i had a look on how to do this but it looks too complicated. all i want is to mail a small .txt as an attachment can anyone help please? i have this code: $to = "a mail adress"; $file = "/home/rainbowcode/StatsFile.txt"; $subject = "StatsFile.txt"; $email = "a mail adress"; $message = "Here is your Statsfile; for today"; $headers = "From: $email"; mail($to, $subject, $message, $headers); can anyone help me please? thanks I send email via simple code of Code: [Select] $message="$description"; $to="email@googlemail.com"; $from="email@hotmail.com"; $headers="From:" . $from; mail($to,$title,$message,$headers); I am looking for the simplest way to add attachment to the email. The instructions given on the internet make the case complicated. I just need to make it simply. Thanks 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!! |