PHP - Help! In Sending Emails Php
Hi guys,
I am using following code for sending out confirmation email after successful transaction to the user. But, I users are not getting any confirmation emails. Can somebody help me out here. May be I am doing wrong in "$to" function as $sender_email is at previous form, So how can I use Session here? If I am wrong here? Any someone help? Many Thanks in advance. $to = "$sender_email"; $subject = "Your Transaction"; $headers = "From: Company <company@abc.com>\n"; $headers .= "Reply-To: Company <company@abc.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; $message = "Dear ".$rs["sender_name"].", ".$_email_nl.$_email_nl; $message .= "Your paid amount ".$amount." ".$rs["currency"]." has been added to desired account.".$_email_nl.$_email_nl; $message .= "Regards,"; $message .= "my company"; mail($to, $subject, $message, $headers); Similar TutorialsHi -- I'm receiving two emails with this code.. one from "webmaster" and another from "serveradmin." What's odd is that the one from serveradmin contains the subject, but not the message. Does anyone know why this is happening and how to fix it so I only receive one email? thanks -- here's the code $usercheck = $_SESSION['user_id']; $check = mysql_query("SELECT * FROM articles WHERE art.id = '$_GET[id]' AND art.user_id = '$usercheck'")or die(mysql_error()); $check2 = mysql_num_rows($check); $recep = "me@gmail.com"; $subject = "Email Subject Line"; $text = "$usercheck"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=UTF-8\r\n"; $headers .= "Reply-to: me@gmail.com\n"; $headers .= "X-Mailer: PHP\n"; if ($check2 != 1) { include_once ("nav_my_account.inc"); mail("$recep","$subject","$text","$headers"); $content = "<p>You can only edit your own articles. <br><br>If you feel you're getting this message in error, it may be that your session has timed out and you need to log back in. </p>\n"; } else { include_once ("nav_my_account.inc"); .....etc.... Hi, Just wondering if you can figure out why this code is sending two emails?? I can't figure it out. <?php $recent=$_GET['recent']; $sendemail=$_GET['sendemail']; mysql_close($conn); $output = 'no'; $dbhost = '*********'; $dbuser = '*********'; $dbpass = '*********'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('MYSQL N/A - Please Contact Admin'); $dbname = 'documentaries'; mysql_select_db($dbname); $query1 = "SELECT * FROM table1"; $result1 = mysql_query($query1); $num1 = mysql_numrows($result1); if(is_int($num1/10)){ $output = 'yes'; } if (($output == 'yes') && ($sendemail == 'yes')) { $query2 = "SELECT * FROM table2"; $result2 = mysql_query($query2); $num2 = mysql_numrows($result2); $i=0; while ($i < $num2) { $email=mysql_result($result2,$i,"email"); $subject = "Subject Here"; $msg = "Message Here"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $eLog="/tmp/mailError.log"; //Get the size of the error log //ensure it exists, create it if it doesn't $fh= fopen($eLog, "a+"); fclose($fh); $originalsize = filesize($eLog); mail($email,$subject,$msg,$headers); /* * NOTE: PHP caches file status so we need to clear * that cache so we can get the current file size */ clearstatcache(); $finalsize = filesize($eLog); //Check if the error log was just updated if ($originalsize != $finalsize) { print "<b>Problem sending mail to $email. (size was $originalsize, now $finalsize) See $eLog...<br>"; } else { print "Mail sent $email<br>"; } $i++; } // redirect } mysql_close($conn); // redirect ?> Thanks For your help! Hey guys! Been a long time since I've posted here but I am back for help because I'm encountering a problem that's kind of baffling me. I'm programming a web game, and one of the things that happens is that an email gets sent out when it's your turn in one of your games. This is working fine and all but I can not for the life of me figure out how to send email with html in it that is universally accepted. What I've been doing so far works for gmail, hotmail, etc. but for some reason breaks entirely when someone opens an email with a client like Thunderbird or Outlook. Here's what I've been doing: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: Admin <admin@examplesite.com>' . "\r\n"; $mail_body = '<html><body>It is now your turn in the game. The game can be viewed <a href="examplesite.com">here</a>.</body></html>'; mail("user@examplesite.com",'New Turn',$mail_body,$headers); Is there something I'm missing? I have literally no experience using Outlook or the like so I don't know if it's a problem with them or if I'm doing something wrong. I'm having an issue with sending HTML Emails. Here is my code, but nothing comes out right when it gets emailed. And my email client is set to view HTML. I can view other HTML emails just fine, but not these. Here is my code to send the email, just wondering whats wrong with it. Thanks for any suggestions. Code: [Select] $full_email = $frm_to . '@scotthermanfitness.com'; //define the receiver of the email $to = $full_email; //define the subject of the email $subject = 'Form Submit - SHF ' . $to_text . ' (' . $frm_name . ')'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: " . $frm_email . "\r\nReply-To: " . $frm_email; //add boundary string and mime type specification //$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; $headers .= " Content-type: text/html\r\n"; //begin of HTML message $message = $frm_content; //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); Hello, I'm trying to send an email with a PDF attachment. The email is sending, but the attachment will not open. Any help you can give is appreciated. Code snippets below: function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { print("mail send ... OK"); // or use booleans here } else { print("mail send ... ERROR!"); } } $my_file = "Adol_Packet_v2.pdf"; $my_path = $_SERVER['DOCUMENT_ROOT']."/homepages/35/d350375870/htdocs/html/"; $my_name = "Company Name"; $my_mail = "atheneris@yahoo.com"; $my_replyto = "atheneris@yahoo.com"; $my_subject = "Welcome Email From Carlock & Associates"; $my_message = "Test Message"; mail_attachment($my_file, $my_path, $email_to, $my_mail, $my_name, $my_replyto, $my_subject, $my_message); I have a form that allows a user to select from several dropdowns, employees who will receive an email message. The email script works fine, however if an employee is selected more than once (which is not a rare) then the employee will receive as many email messages as their name appears. I would like for each employee to only receive the email once. For example: I am the submitter of the form and I am also the coordinator for this particular job. Therefore, my name & email are in the array twice and I will receive two emails on submit. Here is my email script: Code: [Select] $submitter = get_employee_email($user_id); $project_manager = get_employee_email($pm_id); $accountant = get_employee_email($a_id); $coordinator = get_employee_email($pc_id); $contractor = get_employee_email($contractor_id); $director = get_employee_email($dr_id); $to = array($submitter, $project_manager, $accountant, $coordinator, $contractor, $director); foreach ($to as $t){ $headers["From"] = "TEST <TEST@gmail.com>"; $headers["To"] = $t; $headers["Subject"] = "TESTING FOR JOB ID $job_id"; $text = "TESTING. Please review!"; $html = "<html><body>TESTING. Please review!</body></html>"; $file_path = "./$file"; $crlf = "\n"; $name = "TEST.csv"; $smtp_info["host"] = "TEST@gmail.com"; $smtp_info["port"] = "40"; $mime = new Mail_mime($crlf); $mime->setTXTBody($text); $mime->setHTMLBody($html); $content_type = "text/csv"; $mime->addAttachment($file_path, $content_type, $name); $body = $mime->get(); $hdrs = $mime->headers($headers); $SMTP = Mail::factory('smtp',$smtp_info); $mail = $SMTP->send($t, $hdrs, $body); } Hello, I'm using phpmailer for this job, and what I want is that in first mail user gets only text and in second he gets text with attachment. But code below is only sending me the mail with attachment(second mail), what is cosing this problem? Here's the code Code: [Select] for ($i=0; $i<2; $i++) { if (!class_exists("phpmailer")) { require("PHPMailer/class.phpmailer.php"); } if ($price != 0 ) { $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->From = "domain@d.com"; $mail->FromName = "Company"; $mail->AddAddress($email, ""); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = "Subjcet"; $mail->Body = $content; } if ($i == 1 || $price == 0 ) { //require("PHPMailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->From = "domain@d.com"; $mail->FromName = "Company"; $mail->AddAddress($email, ""); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = "Subjcet"; $mail->Addattachment ("file/patch".$fileName, ); // patch and name of an attachment } } So far I just want a basic structure, a database with one table with two values, yes or no. yes would be for email validated, no for email not validated. i just want it so when a user signs up, it sends a unique link to their email to validate their email. I cant even think right now, ive been coding all day and cant even begin to think of how to start this. anybody got any ideas? thanks I handle MySQL errors like this:
function handle_error($err) { throw new Exception($err); } try { $con = mysql_connect("", "", "") or handle_error("mysql_connect failed! "); mysql_select_db("") or handle_error("mysql_select_db failed! "); $sql = "SELECT blah blah blah ..."; $result = mysql_query($sql, $con) or handle_error("mysql_query failed! "); } catch(exception $e) { // Log error in error_log file. trigger_error($e->getMessage() . mysql_error(), E_USER_WARNING); // Send yourself an email. error_log($e->getMessage() . "Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "example@aol.com", "From: example@yahoo.com"); } if(isset($result)) { blah blah blah ... }The problem is, I can receive a huge number of e-mails whenever there's a connection error. How can I limit the number of e-mails that I send myself in the event that my database fails? I really haven't a clue. The only idea that I had was store the time that I sent the first e-mail in a database and then check the database before sending any other e-mails. But this obviously won't work because MySQL won't be working. Any ideas will be much appreciated. I'm curious about the mechanics of the script execution here. One page in my project sends out batch emails to all users who are registered. That part is simlple enough, but in order to do it, my page has to connect to a remote SMTP server and then submit all the recipients and messages. This process can take a little bit of time, usually 5 seconds or so. If the user hits the stop button or navigates away while my script is still executing, will it mess up the emails that are being sent? If so, what other way should I restructure my script to make it more robust? The first thing that comes to my mind is adding them to some sort of queue in the database and then have a separate script that checks periodically for messages that need to be sent and then send them. The only way to do this, though, would be to make a script designed to be called by cron, and that somewhat complicated the installation of my script which I'd like to avoid. Hi, I am using the phpmailer class and a little script I found online, I have a form with a textarea called "plain" which submits and takes the action through to this page: Code: [Select] <?php #include PHPMailer class and database connection include("class.phpmailer.php"); include("connect.php"); #remove slashes from content $plain = stripslashes($_POST["plain"]); #initiate PHPMailer class $mail = new PHPMailer(); #set the from e-mail address $mail->From = "email@email.com"; #set the from name $mail->FromName = "myname"; #the subject of the email $mail->Subject = "Our Newsletter"; #the HTML content of the email $mail->Body = $plain; #loop through e-mail addresses $query = "SELECT email FROM member"; $result = mysql_db_query ("define_pete", $query); while ($myrow = mysql_fetch_array($result)){ #add subscribers address as the recipient $mail->AddAddress($myrow["fldEmail"]); #sends the newsletter $mail->Send(); #clears the recipient address $mail->ClearAddresses(); } ?> It gives no errors and goes through, yet it definitely sends no emails out, I have made sure the emails are correct in the field email in the table member but it is, anyone got any clue what is going wrong? Appreciated I am using PHP Mailer to send out emails to an array of email address. So I am looping through the array of emails and then sending out the emails individually. The script works except it is sending out more than one email to some of the email address. Today my client told me that he got 2 more emails on Sunday just like the 2 he got on Thursday. I am assuming that this has something to do with caching, but I do not know. The trigger that sends out the emails is part of a cron job. The cronjob runs every 30 minutes. Checks to see if there is a new entry in one of the tables in the database. Then it sends out the email to all of the members. After the email is sent a value is changed for that entry in the data base. I am explaining this only to help you to see that the problem is not that the code is being triggered again. If that was the problem then there would be and email every 30 minutes and that is not what happened. Here is the code: <?php require_once('library/PHPMailer/class.phpmailer.php'); require_once('library/PHPMailer/class.smtp.php'); foreach($organizationemails as $key => $value){ $contents = '<body> <div> <p> ...content of email ... </p> </div> </body>'; error_reporting(E_ALL); error_reporting(E_STRICT); $mail = new PHPMailer(); $body = $contents; $body = preg_replace('/[\]/','',$body); $mail->IsSMTP(); $mail->Host = "ssl://smtp.mysite.org"; $mail->SMTPAuth = true; $mail->Port = 465; $mail->Username = "sendingmail@mysite.org"; $mail->Password = "password"; $mail->SetFrom('info@mysite.org', 'My Organization'); $mail->AddReplyTo('info@mysite.org', 'My Organization'); $mail->Subject = 'My Email Title'; $mail->AltBody = '... has been posted...'; $mail->MsgHTML($contents); $address = $value; $mail->AddAddress($address); if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; }else{ echo "Message has been sent to ".$value; } } ?> 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.
Hello, recently I changed host of my website and when a visitor clicks "contact us" button in my website (in which one needs to enter his/ her email, name, phone , etc) and submit his/her message then I get email. Before this hosting I used to get emails from the visitor who filled the form so it was easier for me to reply but now after I changed the host I get email as "mydomain@hosting-company-domain" instead of the visitor's email. I messaged them then they told me something about SMTP authenticate using PHP, please guide me to fix this. 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 want to implement a program for identifying spam emails using an algorithm naive bayes in php.. How to implement this ..can any one help me.. thanks in advance I am trying to go through all of the emails in an inbox with php. I saw a way to do it with imap_open, but I don't have the imap functions installed. Does anyone know of another way to do this? I would think someone would have written a 3rd party library that just uses sockets -- kind of like phpmailer but for receiving instead of sending. Hi This subject doesn't really have a category but is driving me mad. I use the mail() function to send out emails to a news group forum that I have created. This forum does the same. I am getting the emails placed in a spam folder. Is there any way around this. I have been told that it has something to do with no reverse DNS. I get emails like DoNotReply@bt.com. This email address doesn't exist. How does the email system know this, and is there a way around it. TIA Desmond. hi i need to send around 1000 emails per day to my website users as notifications on their activities and also need bulk email capability to target 20000 users at a time when required. I am currently using gmail smtp but it has restrictions on the both bulk mailing and the no. of emails that can be sent in a day . What should i do ?? Any suggestions would be appreciated. Thanks hi i am new on php+mysql i am trying to create signup form that will: users to enter email address and the script check via ajax from MYSQL database if the email is not registered send the signup link to their email if already registered than show error you are a member. |