PHP - Sending Mail Function Attachments With Php Mail() Function
Hello Everyone
I have written a simple mail function to be emailed to a certain person on submission. On submission they would also like to have attachments sent to them. I got the email being sent but I can;t get the attachments to work. I have read several different examples and tutorials and none of them work. This is my code so far without any code for file attachment <?php $project_name = $_POST['project_name']; $needed = $_POST['date_needed']; $submitted = $_POST['date_submitted']; $department = $_POST['department']; $contact = $_POST['contact_person']; $extension = $_POST['extension']; $project_type = $_POST['project_type']; $published = $_POST['date_last_published']; $description = $_POST['description']; $color = $_POST['color']; $pdf = $_POST['pdf_needed']; $web = $_POST['web_needed']; $quanity = $_POST['quanity']; $email = "mdmartiny@sc4.edu"; $subject = "SC4 Graphics Design Service Request Form"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message = "<html><body> <table width=\"100%\" border=\"0\" cellspacing=\"5px\" > <tr><td></td> <td>Project name: $project_name</td> <td></td> <td>Date needed by: $needed</td> </tr> <tr> <tr> <td></td> <td colspan=\"3\" align=\"left\" valign=\"top\"><strong><font size=\"+1\">Submitted to graphic designer</font></strong></td></tr> <tr><td height=\"25\"></td><td>Date $submitted</td><td>Department $department</td><td></td></tr> <tr><td height=\"25\"></td><td>Contact Person $contact</td><td>Extension $extension</td><td></tr> <tr><td height=\"25\"></td><td>Type of project $project_type</td><td colspan=\"2\">Approximate date of last publication $published</td></tr> <tr><td height=\"25\"></td><td colspan=\"3\">Project description/special instructions</td> <tr><td></td>><td colspan=\"3\">$description</td></tr> <tr><td height=\"25\"></td><td>Color $color</td><td>PDF needed $pdf</td><td>Website update needed $web</td></tr> <tr><td ></td><td>Estimated print quanity $quanity</td><td></td><td></td></tr> <tr> <td colspan=\"4\" align=\"left\" valign=\"top\"><hr height=\"5\"/> <strong><font size=\"+1\">Graphics office use only</font></strong></td> </tr> <tr> <td height=\"25\" width=\"2%\"> </td> <td width=\"34%\">Print Shop Color copier</td> <td colspan=\"2\">Print Vendor_______________________________________</td> </tr> <tr> <td height=\"25\"> </td> <td><strong><font size=\"+1\">Project tracking</font></strong></td> <td> </td> <td> </td> </tr> <tr> <td height=\"25\"> </td> <td colspan=\"3\">Received by graphic designer_______________________ Date _______</td> </tr> <tr> <td height=\"25\"> </td> <td colspan=\"3\"> <table width=\"100%\" height=\"35\"> <tr> <td>Approved by executive director__________ Date_________</td><td><input type=\"checkbox\"> Revisions needed<br /><input type=\"checkbox\"> Revisions made ______ Date_______</td><tr> </table> </td> </tr> <tr> <td height=\"25\"> </td> <td colspan=\"3\">Completed and spell checked by graphic designer___________________________ Date__________</td> </tr> <tr> <td> </td> <td align=\"center\" colspan=\"3\"> <table cellpadding=\"10px\" cellspacing=\"0\" border=\"1\" width=\"100%\"> <tr bgcolor=\"#CCCCCC\"> <td> <table> <tr> <td> Proofread by marketing coordinator __________ Date__________</td> </tr> <tr> <td> Proofread by secretary __________ Date__________ </td> </tr> </table> </td> <td> <input type=\"checkbox\"> Revisions needed <br> <input type=\"checkbox\"> Revisions made ____ Date_____ </td> </tr> </table></td> </tr> <tr> <td></td> <td colspan=\"3\"> <table width=\"100%\" height=\"75\"> <tr> <td>Proofread by executive director______ Date______ </td><td><input type=\"checkbox\"> Revisions needed<br /> <input type=\"checkbox\"> Revisions made ______ Date_______</td> </tr> </table> </td> </tr> <tr> <td></td> <td colspan=\"3\"> <table width=\"100%\" height=\"75\"> <tr> <td> Approval by requesting department __________ Date_________ <br /> <strong><font size=\"-1\">(Include all paperwork when returning)</font></strong></td><td><input type=\"checkbox\"> Revisions needed<br /><input type=\"checkbox\"> Revisions made ______ Date_______</td> </tr> </table> </td> </tr> <td></td height=\"25\"> <td colspan=\"3\">Final approval by executive director _________________________________________ Date_________ </td> </tr> <tr> <td height=\"75\"></td> <td><input type=\"checkbox\"> Printed ____ Date _____</td> <td colspan=\"2\"><input type=\"checkbox\"> PDF created _____ Date _____<br /> <input type=\"checkbox\"> Website updated _____ Date _____</td> </tr> </table>"; $message .= "</body></html>"; mail($email, $subject, $message, $headers, "From: $email"); echo "The email has been sent."; ?> Similar TutorialsI found the below code so I can attach a file to a email message, but there is a small problem I need some help with. The script works beautifully except for the fact that when message is received the attached file does not contain a file extension. I am able to open the attachment but I am receiving the windows dialog box that asks: "Choose the program you want to open this file". I intend on only using this script to attach HTML files so I am wondering if there is a way to make the file extension of the attachment read as .html? That way when the user receives the attachment it will automatically open with there default browser. Code: [Select] <?php $to = "test@test.com"; $from = "test@test.com"; $subject = "AHC"; $message = "hello world"; $fileatt = $_SERVER['DOCUMENT_ROOT']."/home-care-information/test.html"; $fileatt_type = "multipart/alternative"; //This is where the problem is I think $fileatt_name = "Application"; $headers = "From: $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}\""; $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"; $data = chunk_split(base64_encode($data)); $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($to, $subject, $message, $headers); if ($ok) { echo "<p>Mail sent! Yay PHP!</p>"; } else { echo "<p>Mail could not be sent. Sorry!</p>"; } ?> Hi all Im sending a dynamic created pdf file with php. It gets flagged as spam are things that can be done to help prevent this ? didnt really know where to post it. Hello, I'm using php's mail function to send sms messages to my sprint phone. Sometimes I receive the text right away and other times it comes in as much as an hour or so later. My server is on GoDaddy. Does anyone have any ideas about what could be causing the bottleneck? To debug this I tried sending sms messages from my comcast email. So far those are always received very quickly. Perhaps the issue is on the GoDaddy server... I might try contacting them. By the way, it seems like the first text I send is received quickly, but then if I send other text messages within some short time frame, those don't always show up immediately. Has anyone else experienced anything similar? 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); $to=sammieave@ave.com,samuel@ave.com; $subject = "New Event Logged"; $message = "Test"; $headers = "From: Samuel<sammieave@ave.com>;\r\n"; $headers .= "Content-Type: text/html"; mail($to,$subject,$message,$headers); I am having the above code but unfortunately the error I am getting is: Warning: mail() [function.mail]: SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\xampp\htdocs\CRM\support\mailer.php on line 139 I am using magento for sending mail with condition, My code: <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $extra = $order->getIncrementId(); $message = " <tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = " <p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body ="$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('abc'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $emailTemplate->setToEmail('abc@gmail.com'); $emailTemplate->send(); } } ?>
Output :
If order placed mail send to abc@gmail.com. I want :
1) If SKU starts with 2, email should go to the mail id abc@gmail.com,
2) If SKU starts with 3, email should go to the mail id xyz@gmail.com,
3) If SKU starts with 4, email should go to the mail id qwe@gmail.com,
FYI - If an order contains 10 items email should go separately based on SKU. But an order id the same must include all the emails.
Hi all, I'm coding an automated mailer for a dentist office. They set appointment dates through a web interface, and then this appointment is mailed to the customer via PHP's mail() function. However, some users are not receving the mail. They claim that it is not even in the junk mail folder. Is it because I'm setting or not setting certain properties in the header? Should I be setting something else? Here is my code Code: [Select] ini_set("SMTP", "mail.isp-provider.net"); $headers = 'From: Schedule Manager <schedule@address.com>' . "\r\n" . 'Reply-To: Schedule Manager <schedule@address.com>' . "\r\n" . 'Bcc: internal@address.com' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($customerAddress, $subject, $body, $headers); Note that customerAddress, subject, and body are all just regular normal strings. As I said, it works for most customers, but some customers do not receive the emails. Hello there, I've come across a issue with using PHP's mail function due to the fact I've tried a assortment of different headers yet Hotmail continues to place my sent emails in the junk folder. Here is my method of emailing my clients: function Email($AccountID, $Subject, $Message) { if($this->IsValidAccount($AccountID)) { $Account = $this->AccountKeys($AccountID); $headers .= 'To: '.$Account['account_client'].' <'.$Account['account_email'].'>' . "\r\n"; $headers .= "From: X-Host <no-reply@X-Host.co.uk>\r\n"; $headers .= "Reply-To: X-Host <no-reply@X-Host.co.uk>\r\n"; $headers .= "Return-Path: no-reply@X-Host.co.uk\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "Organization: X-Host\r\n"; echo $Account['account_email']. $Subject. $Message; return mail($Account['account_email'], $Subject, $Message, $headers); } else return InvalidAccount; } So could anybody help me out please and tell me what headers I should be using. Everything about the email is sending except the message text does anyone know what the issue could be? here is the block of code that sends the email Thanks in advance Code: [Select] $image = "http://www.visualrealityink.com/dev/clients/arzan/snell_form/images/email.png"; echo "got to process form"; $target_path = "upload/"; $path = $target_path = $target_path . basename( $_FILES['file']['name']); $boundary = '-----=' . md5( uniqid ( rand() ) ); $message .= "Content-Type: application/msword; name=\"my attachment\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment; filename=\"$path\"\n\n"; echo $path; $fp = fopen($path, 'r'); do //we loop until there is no data left { $data = fread($fp, 8192); if (strlen($data) == 0) break; $content .= $data; } while (true); $content_encode = chunk_split(base64_encode($content)); $message .= $content_encode . "\n"; $message .= "--" . $boundary . "\n"; $message .= $image . "<br />" . $_POST['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"; $headers = "From: \"Me\"<me@example.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\""; mail('george@visualrealityink.com', 'Email with attachment from PHP', $headers, $message); 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????? 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, is there a way to generate attachemtns for php's mail() function on the fly, without first saving a file. I have an html page stored in a variable and would like to send it as both the body of the mail and as an attachment in it (well actualy I would like to just send it in the body....). Can I push the variable as an attachement or do I need to generate a temp file from it first? Cheers Hi I am creating a simple program to send e-mail. It contains 2 pages, index.php and sendmail.php Here is the code of index.php 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Send Mail #1</title> </head> <body> <p> </p> <p> Mail 1</p> <form id="form1" name="form1" method="post" action="sendmail.php"> <table width="821" height="240" border="0"> <tr> <td width="168">To :</td> <td colspan="2"><label> <input name="to_textbox" type="text" id="to_textbox" size="75" /> </label></td> </tr> <tr> <td>Subject :</td> <td colspan="2"><label> <input name="subject_textbox" type="text" id="subject_textbox" value="" size="75" /> </label></td> </tr> <tr> <td>From :</td> <td colspan="2"><label> <input name="from_textbox" type="text" id="from_textbox" value="" size="75" /> </label></td> </tr> <tr> <td>Content :</td> <td colspan="2"><label> <textarea name="content_textbox" id="content_textbox" cols="75" rows="5"> </textarea> </label></td> </tr> <tr> <td> </td> <td width="153"><label> <input type="submit" name="send_button" id="send_button" value="Send..." /> </label></td> <td width="486"><label> <input type="reset" name="reset_button" id="button" value="Reset" /> </label></td> </tr> </table> <p> </p> <p> </p> <p> </p> </form> <p> </p> </body> </html> Code for sendmail.php 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $to = $_POST["to_textbox"]; $from = $_POST["from_textbox"]; $subject = $_POST["subject_textbox"]; $message = $_POST["content_textbox"]; $headers = "From: " . $from . "\r\n"; $mailsent = mail($to, $subject, $message, $headers); if ($mailsent) { echo " <center> Congrats ! The message has been sent </center>"; echo " <center><b>\n To: $to </b></center>"; } else { echo " There was an error..."; } ?> </body> </html> How can I add attachments ? I want to add few photos (.jpg) I searched on google but found nothing which can relate with mail() Hello, i have this code for sending email it works great but i don't know where to start in sending emails with a pdf file attached ex: test.pdf. Any suggestions? <?php session_start(); require_once('framework/framework.php'); include('framework/class.smtp.inc'); //--- databse settings $dsn = array( 'dbtype' => 'mysql', 'username' => '', 'password' => '', 'host' => '', 'database' => '' ); try { $db = db::connect($dsn); } catch (Exception $e) { die($e->getMessage()); } //--- $subject="Formular online pentru participantii Diaspora Stiintifica 2010"; // +-------------- BEGIN ---- Functia de trimitere mail prin smtp -------------------+ */ function trimite($destinatar='', $subiect='', $mesaj='') { //--- mail settings $smtp_server_host="mail.server.com"; $smtp_server_port="25"; $sender="email@email.com"; $return_path="email@email.com"; $smtp_username="email@email.com"; $smtp_pswd="123"; /*************************************** ** Setup some parameters which will be ** passed to the smtp::connect() call. ***************************************/ $params['host'] = $smtp_server_host; // The smtp server host/ip $params['port'] = $smtp_server_port; // The smtp server port $params['helo'] = exec('hostname'); // What to use when sending the helo command. Typically, your domain/hostname $params['auth'] = false; // Whether to use basic authentication or not // $params['user'] = $smtp_username; // Username for authentication // $params['pass'] = $smtp_pswd; // Password for authentication $params['timeout'] = '60'; /*************************************** ** These parameters get passed to the ** smtp->send() call. ***************************************/ $send_params['recipients'] = $destinatar; // The recipients (can be multiple) $send_params['headers'] = array( "MIME-Version: 1.0", "X-Mailer: PHP/" . phpversion(), "Return-Path: ".$return_path, "From: ".$sender, "To: ".$destinatar, "Subject: ".$subiect, "Content-type: text/html; charset=UTF-8", "Content-Transfer-Encoding: 8bit"); $send_params['from'] = $sender; // This is used as in the MAIL FROM: cmd // It should end up as the Return-Path: header $send_params['body'] = $mesaj; /*************************************** ** The code that creates the object and ** sends the email. ***************************************/ $smtp = new smtp($params); $smtp->connect(); $trimis=$smtp->send($send_params); $raspuns=array($destinatar, $trimis, $smtp->errors); // $smtp->rset(); //--- Bcc: /* $send_params['recipients'] = $sender; $trimisi=$smtp->send($send_params); $errmsgi=$smtp->errors; print "<br>bcc: ".$send_params['recipients']."; ".$trimisi."<br>"; for ($n = 0 ; $n <= count($errmsgi) - 1; $n++) { print "<br>"." bccerr: <strong>".$errmsgi[$n]."</strong><br>"; } */ $smtp->quit(); return $raspuns; } // +-------------- END ---- Functia de trimitere mail prin smtp -------------------+ */ // +---------------------------------------------------------------------------+ $afisez = ""; $cond=0; $query = "SELECT email_1 FROM inregistrari WHERE `completat`=0"; $useri = $db->getAll($query); $i=0; $j=0; $k=0; foreach ($useri as $row) { $tpl = new HTML_Template_Sigma('mesaj'); $tpl->loadTemplateFile("mesaj.html"); $tpl->setVariable($row); $html=$tpl->get(); //*/ $html=nl2br($html); $html=str_replace(chr(10), "", $html); $html=str_replace(chr(13), "", $html); // */ // +----------------------+ $subiect = $subject; if (!empty($row['email_1'])) { $subelements=preg_split("/, /", $row['email_1'], -1, PREG_SPLIT_NO_EMPTY); for ($m = 0 ; $m <= count($subelements) - 1; $m++) { $rez = trimite($subelements[$m], $subiect, $html); if ($rez[1]==true) { $afisez .= $rez[0].";1<br>"; $i++; } else { $afisez .= $rez[0].";0<br>"; $errmsg=$rez[2]; for ($n = 0 ; $n <= count($errmsg) - 1; $n++) { $afisez .= " <strong>".$errmsg[$n]."</strong><br>"; } $j++; } } } else { $afisez .= $row['email_1'].";no email;n<br>"; $k++; } } $afisez .= "<br>{$i} mesaje Trimise<br>"; $afisez .= "{$j} mesaje Netrimise<br>"; $afisez .= "{$k} mesaje fara adresa<br>"; print $afisez; ?> is there a way to make a mail function submit only once? so that if you go forward a page, then back, it won't resubmit? Hello, I am using php to send verification links for my website.The registration form sends data to xyz.php(using AJAX) and the response(echo'd part of xyz.php) is returned and shown to the user. The problem i am facing is that the function "$mail->Send()" is echoing the smtp server response.How can i stop this function from echo'in anything. Please reply asap. How do I include .$email to the mail function. this is my current code: mail($to, $subject, "", $headers); I want do it like this; mail("me@myweb.com".$email, $subject, "", $headers); Thanks Bickey. ok, so I have this code and I need to know how to modify it so that the strings display properly............so that it wont display $string but instead whatever value it is.........can you please help: Code: [Select] $to = "$email"; // Change this to your site admin email $from = "events@site.net"; $subject = "Complete your registration"; //Begin HTML Email Message where you need to change the activation URL inside $message = '<html> <style type="text/css"> #apDiv1 { position:absolute; left:338px; top:278px; width:311px; height:129px; z-index:1; } #apDiv2 { position:absolute; left:50px; top:207px; width:181px; height:149px; z-index:2; } #apDiv2 { text-align: center; } </style> </head> <body><div id="apDiv1"> <table width="408" border="1" cellspacing="2" cellpadding="2"> <tr> <th width="90" scope="col">Event(s):</th> <th width="298" scope="col"> $sql = mysql_query("SELECT * FROM Registration WHERE eventid=".$_GET["eventid"]." LIMIT 1"); while($row = mysql_fetch_array($sql)){ $event = $row["event"]; $startdate = $row["startdate"]; $enddate = $row["enddate"]; $description = $row["description"]; $location = $row["location"]; $subevent1 = $row["subevent1"]; $subevent2 = $row["subevent2"]; $subevent3 = $row["subevent3"]; $subevent4 = $row["subevent4"]; $subevent5 = $row["subevent5"]; $subevent6 = $row["subevent6"]; $subevent7 = $row["subevent7"]; $subevent8 = $row["subevent8"]; //this will echo the contents of each db row as they are iterated in the loop ############################# if (!empty($title1)) { echo "<br/>$title1:"; } if (!empty($title2)) { echo "<br/>$title2:" ; } if (!empty($title3)) { echo "<br/>$title3:"; } if (!empty($title4)) { echo "<br/>$title4:"; } if (!empty($title5)) { echo "<br/>$title5:"; } if (!empty($title6)) { echo "<br/>$title6:"; } if (!empty($title7)) { echo "<br/>$title7:"; } if (!empty($title8)) { echo "<br/>$title8:"; } } //etc etc </th> </tr> <tr> <th>Price:</th> <th> $total = $price1 + $price2 + $price3 = $price4 + $price5 + $price6 + $price7 + $price8 ; echo $total; </th> </tr> <tr> <th>Registrant:</th> <th><?php echo $name; ?></th> </tr> </table> </div> <div id="apDiv2"><?php echo $name; ?> <p> </p> <p> </p> <p><a href="index.php" target="_new"><strong>Troop 78 Home</strong></a></p> <p> </p> <p> </p> <p><strong><"></a></strong></p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> </div> <img name="boyscout" src="button/boyscout.jpg" width="1180" height="700" border="0" id="boyscout" alt="" /> </body> </html>'; // end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; $to = "$to"; // Finally send the activation email to the member mail($to, $subject, $message, $headers); // Then print a message to the browser for the joiner print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br /> We just sent an Activation link to: $email<br /><br /> <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br /> Link inside the message. After email activation you can log in."; $to = "@gmail.com"; // Change this to your site admin email $from = "events@site.net"; $subject = "New Registration for $event"; //Begin HTML Email Message where you need to change the activation URL inside $message = '<html> <body> Hello, Aaron $name has registered for $event. they will owe $total = $price1 + $price2 + $price3 = $price4 + $price5 + $price6 + $price7 + $price8 ; echo $total; </body> </html>'; // end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; $to = "$to"; // Finally send the activation email to the member mail($to, $subject, $message, $headers); // Then print a message to the browser for the joiner print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br /> We just sent an Activation link to: $email<br /><br /> <strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br /> Link inside the message. After email activation you can log in."; |