PHP - Php Mail Doesn't Always Send
Hey guys,
I always get a "1" return form php mail, but with the large number of users, 10% aren't getting the email, so they are all constantly emailing me asking me help with their contact info. The email address that im sending from is noreply@mydomain.com its the actual domain of the site. I'm using swfit mailer, but i've done this with just normal mail. When asked about spam, some customers said it went there, but most didn't, they just never got it. How can i reliably send email to my customers? Thanks! Similar TutorialsThis topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 Can somebody tell me how to make this exact code send mail? I tested it on my website and it doesn't send any emails. The first code is the file contact_config.php <?php $mailto = "youremail@email.com"; $charset = "windows-1251"; $subject = "Site visitor: ".$_POST['posName']; $content = "text/html"; $message = "Site visitor information: <br><br> Name: ".$_POST['posName'] ."<br>E-mail: ".$_POST['posEmail'] ."<br>Country: ".$_POST['posCountry'] ."<br>Phone: ".$_POST['posRegard'] ."<br>Comments: ".$_POST['posText']; $statusError = ""; $statusSuccess = ""; $errors_name = 'Please enter the Name'; $errors_mailfrom = 'Please enter the Email'; $errors_incorrect = 'The e-mail address you entered does not eppear to be valid. <br>Your e-mail address should look like yourname@domain.com'; $errors_message = 'Please enter the Message'; $errors_subject = 'Please enter the Phone'; $captcha_error = 'Wrong security code!'; $send = 'Thank you for your message'; ?> <?php $mailto = "youremail@email.com"; $charset = "windows-1251"; $subject = "Site visitor: ".$_POST['posName']; $content = "text/html"; $message = "Site visitor information: <br><br> First Name: ".$_POST['posName'] ."<br>Last Name: ".$_POST['posName2'] ."<br>E-mail: ".$_POST['posEmail'] ."<br>Telephone: ".$_POST['posRegard'] ."<br>City where jobsite is located: ".$_POST['posText'] ."<br>want us to e-mail you the free Homeowners Guide To Remodeling: ".$_POST['posBox']; $statusError = ""; $statusSuccess = ""; $errors_name = 'Please enter the First Name'; $errors_name2 = 'Please enter the Last Name'; $errors_telephone = 'Please enter the Telephone'; $errors_city = 'Please enter the City where jobsite is located'; $errors_mailfrom = 'Please enter the Email'; $errors_incorrect = 'The e-mail address you entered does not eppear to be valid. <br>Your e-mail address should look like yourname@domain.com'; $captcha_error = 'Wrong security code!'; $send = 'Thank you for your message'; ?> The second code is contacts.php <?php include('kcaptcha/kcaptcha.php'); session_start(); require_once("contact_config.php"); if ($_POST['act']== "y") { if(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] == $_POST['keystring']) { if (isset($_POST['posName']) && $_POST['posName'] == "") { $statusError = "$errors_name"; } elseif (isset($_POST['posEmail']) && $_POST['posEmail'] == "") { $statusError = "$errors_mailfrom"; } elseif(isset($_POST['posEmail']) && !preg_match("/^([a-z,._,0-9])+@([a-z,._,0-9])+(.([a-z])+)+$/", $_POST['posEmail'])) { $statusError = "$errors_incorrect"; unset($_POST['posEmail']); } elseif (isset($_POST['posText']) && $_POST['posText'] == "") { $statusError = "$errors_message"; } elseif (!empty($_POST)) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: $content charset=$charset\r\n"; $headers .= "Date: ".date("Y-m-d (H:i:s)",time())."\r\n"; $headers .= "From: \"".$_POST['posName']; $headers .= "X-Mailer: My Send E-mail\r\n"; mail("$mailto","$subject","$message","$headers"); $_POST['posRegard'] = ""; $_POST['posText'] = ""; $_POST['posCountry'] = ""; $_POST['posEmail'] = ""; $_POST['posName'] = ""; unset($name, $posText, $mailto, $subject, $posRegard, $message); $statusSuccess = "$send"; } }else{ $statusError = "$captcha_error"; unset($_SESSION['captcha_keystring']); } } $cat_name="Contact $store_name manager"; ?> Now for some reason the two of these files are supposed to send me emails when customers click the submit email button on my form but, I don't get any emails. I tested it myself and no emails. Help please! I'm trying to send email with php for the first time. Trying to make it so that after a user registers he/she receives an email after submitting. I'm trying to send it from 1 comp with an email of goldie@telkomsa.net to another with an email of jgoldie@telkomsa.net (I just really want to test if it's sending email another before I get technical with the email) Should this code work, here is part of my code with the email section in it: Code: [Select] <?php // query $sql = "INSERT INTO student (sno, sname, init, fname, title, msname, dob, sex, lang, idno, telh, telw, cel, fax, email, address, contact_flag ) VALUES ('', '$sname', '$init', '$fname', '$title', '$msname', '$dob', '$sex','$lang', '$idno', '$telh', '$telw', '$$cell', '$fax', '$email', '$address', '$contact')"; mysql_query($sql) or die('Error:' . mysql_error()); $sno_id = mysql_insert_id(); // get the cid $cname = mysql_real_escape_string($_POST['cname']); $getCID = "SELECT cid FROM course WHERE cname='$cname'"; $result = mysql_query($getCID); if($result) { $row = mysql_fetch_assoc($result); $course_id = $row['cid']; // add the student to the course_student table $addCID = 'INSERT INTO course_student (cid, sno) VALUES(' . $row['cid'] . ', ' . $sno_id . ')'; mysql_query($addCID) or die('Error:' . mysql_error()); // send email $Name = "Da Duder"; //senders name $email = "goldie@telkomsa.net"; //senders e-mail adress $recipient = "jgoldie@telkomsa.net"; //recipient $mail_body = "The text for the mail..."; //mail body $subject = "Subject for reviever"; //subject $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields ini_set('sendmail_from', 'goldie@telkomsa.net'); //Suggested by "Some Guy" if (mail($recipient, $subject, $mail_body, $header)){ echo "mail has been sent"; //mail command } } header( "refresh:5;student_man.php" ); echo 'Registration <b> successful </b> You\'ll be redirected in about 5 secs. If not, click <a href="student_man.php">here</a>.'; } } ?> Email is under the "email section" comment based of what I found on google. I'm not getting any errors so I want to know if the email isn't going through because of my code or my smtp setting etc. I understand you need to use the mail() command but this just wont work for me, my webserver is with godaddy, and they sent me an email saying that i need to use a relay server to send my mail, how do i set this up or anything? Hi People,
I'm using a php to send an mail using a server via ssl. My program:
<?php Hello, I have those code: $message = " Hello $inforow2['company']<br /> This is a notice about a pending invoice at $inforow3['company'].<br /> If you would like to see the invoice, you can see it <a href='http://$inforow3['url]'/view-invoice?id=$id.php'>here</a><br /> This is an automatic message. Replies will not be monitored.<br /> Yours faithfully<br />$inforow3['company']"; mail($inforow2['email'],"Invoice overdue #1",$message,$inforow3['sentfrom']); I'm not sure if I can send this, and it will get the values from my mysql and put it in the email or it would send the text directly, and if it ill take the html.. Can any one tell me if above code would be correct? Hello, I have been using the mail() command for a while now, but for some reason It has just stopped functioning all together. I have added an OR DIE rule to the end of it and had no response. To all intents and purposes that mail is being sent - there are no errors whatsoever - just the mail is not getting delivered. I cannot think of anything I've done or changed that would stop it from being delivered, I haven't even been near the function that does it in a while. Here is the code: Code: [Select] function sendMail($to,$ref) { $subject = 'Booking Confirmation'; $file = "receipts/$ref.htm"; $fh=fopen($file, "r"); $message = fread($fh, filesize($file)); fclose($fh); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: Company <noreply@company.co.uk>' . "\r\n"; mail($to, $subject, $message, $headers); } I have taken out the public names involved, but otherwise thats the code. It has worked absolutely fine in the past, and even If I strip out all of the filehandling part of it, and just use a simple $from - $to - $message, it still seems not actually send the mail. It wouldnt be so bad If I at least had an error to go on, but I dont I am just simply not getting the mail. Please help! ~Chud37 this worked and stopped, no error no idea why is this a conflict? Code: [Select] echo("<meta http-equiv = refresh content=0;url=".$url_success.">"); mail($to_supplier, $subject_supplier, $message_supplier, $headers_supplier); $ok = @mail($email_to, $email_subject, $email_message, $headers); Hi guys, I'm sending mail from php running on a cheap webhost with the following: Code: [Select] $to = 'name@domain.com.au'; $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $header .= "From: Name <noreply@domain.info>" . "\r\n"; $subject = "Interest registered"; $message = "<!DOCTYPE HTML.. a bunch of html"; mail($to, $subject, $message, $header); As you can see I've set "from" in the headers. When I receive the email however, it says from: myusername@my.cheaphost.com on behalf of Name [noreply@domain.info] I need to get rid of the on behalf bit as it looks completely unprofessional. I just want it to say from: Name [noreply@domain.info] Obviously this is probably something to do with the setup of the server, some of which I have no control over. I have access to another mail server which I can use to send email, so I put this at the start of my code: Code: [Select] ini_set('SMTP', 'mail.myotherserver.com.au'); echo ini_get('SMTP'); Which returns mail.myotherserver.com.au however, when I use the mail function, it still comes from myusername@my.cheaphost.com on behalf of Name [noreply@domain.info] Is there something I'm missing, is the mail function not tied to the SMTP value? Thanks Hallo guys!! I have this script Code: [Select] <?php $name = mysql_real_escape_string($_REQUEST['name']); $link = mysql_real_escape_string($_REQUEST['link']); $filename = mysql_real_escape_string($_REQUEST['filename']); if(empty($name) || empty($link) || empty($filename))exit; mysql_connect('localhost','root',''); @mysql_select_db('1') or die( "Unable to select database"); if (!mysql_query("INSERT INTO `1`.`files` (`name`,`link`,`filename`) VALUES ('$name','$link','$filename');")) { echo 'Fail!'; exit; } else { echo "Succesfuly added!"; } mysql_close(); ?> works fine when they send me link to mydomain.com/script.php?name=1&link=2&filename=3 and database updates fine , but the idea is That each name is owned by a group and every group has a different email adresse , how can automatically send email at the time someone send a link to my adress (mydomain.com/script.php?name=1&link=2&filename=3) with few words i want to notify the owner of the group (name) for the link and filename values Thats the story Thanks!!! This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=346693.0 Hey my name is Brandon, im quite new to php but im improving and I really want to get into web design soon. Well lucky for you guys I was bored so i decided to create a Contact Us page. Just so you know MY contact us requires the user to be logged in to use it otherwise it redirects them to the login.php page and outputs a error saying "you need to be logged in to access this page", however i changed this contact us page so the user does not have to be logged in and it just requires all the fields to be entered. One thing I diden't add was a system to check if the email has a "@" sign in it, so you can be more confident that the email is real, I don't find this that important because if the user is leaving out a "@" sign then it's likely they are just wanting to send a fake email and they will do it regardless of a check or not. Here's The Code. <?php function mysql_prep($value) { $magic_quotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists("mysql_real_escape_string"); // i.e PHP >= v4.3.0 if($new_enough_php){ // PHP v4.3.0 or higher if ($magic_quotes_active){ $value = stripslashes($value); } $value = mysql_real_escape_string($value); }else{ //Before PHP v4.3.0 //if magic quotes aren't already on then add slahes manually if(!$magic_quotes_active){ $value = addslashes($value); } // if magic quotes are active then the slashes already exist } return $value; } function redirect_to($location = NULL){ if($location != NULL){ header("Location: {$location}"); exit; } } ?> <?php if (isset($_POST['submit'])){ // The form has been submitted $errors = array(); // Perform validations on the form $required_fields = array('title', 'email', 'message'); foreach($required_fields as $fieldname){ if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])){ $errors[] = $fieldname; } } $field_with_lengths = array('title' => 20, 'email' => 50); foreach($field_with_lengths as $fieldname => $maxlength) { if (strlen(trim($_POST[$fieldname])) > $maxlength) { $errors[] = $fieldname; } } // Set the needed variables here $email = $_POST['email']; $title = $_POST['title']; $message = $_POST['message']; if (empty($errors)){ // Their are no errors in the form $headers = 'From: ' . $email . "\r\n" . 'Reply-To: bcooperz@hotmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $sentmail=mail("bcooperz@hotmail.com","$title","$message", "$headers"); // if your email successfully sent if($sentmail){ echo "Your Email Has been sent"; }else{ echo "Cannot send email"; } }else{ $count = count($errors); if($count == 1){ echo "Their Was {$count} Error In The Form" . "<br />"; echo "<b>"; print_r(implode(", ", $errors)); echo "</b>"; }else{ echo "Their Was {$count} Error's In The Form" . "<br />"; echo "<b>"; print_r(implode(", ", $errors)); echo "</b>"; } } }else{ // The Form Has Not Been Submitted $email = ""; $title = ""; $message = ""; } ?> <html> <head> <title>Contact Us</title> </head> <body> <form action="contact.php" method="post"> Title of message : <input type="text" name="title" maxlength="20" value="" /><br /> Your Email : <input type="text" name="email" maxlength="50" value="" /><br /> Message : <br /><textarea name="message" rows="20" cols="80"></textarea><br /><br /> <input type="submit" name="submit" value="Contact Us" /><br /> </form> </body> </html> Now in order for this to work you will need to have a domain or localhost will also do fine if you have it set up with a email system, some free domains will work as long as they have a email sending capability and php enabled. Also one thing you will want to do is change "bcooperz@hotmail.com" in that code to your email so the users of your website are sending the emails to your email Thanks, BcooperZ. I need this form to be sent to a mail after you press the button and to see the content that is sent , what is the easiest way to do this? http://fhcs.be/ Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions session_start(); $dranken=array(); $DrinkResult=mysql_query("SELECT name,price FROM products" )or die(mysql_error()); while($DrinkRow=mysql_fetch_assoc($DrinkResult)) { $dranken[]=$DrinkRow; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head></head> <body> <?php if (!isset($_POST['submit'])) { ?> <form method="post" action="mail.php"> <input type="submit" value="Toon Output" name="submit"/> <?php echo "<table>"; foreach ($dranken as $DrinkRow) { $optionlist = "<select name='{$DrinkRow['name']}_aantal'>"; for($i=0;$i<10;++$i) { $optionlist .= "<option value='$i'>$i</option>"; } $optionlist .= "</select>"; echo "<tr><td>". $DrinkRow['name']."</td><td>".$DrinkRow['price']."</td>"; echo "<td>$optionlist</td></tr>"; } echo "</table>"; ?> </form> <?php } else { echo "<table>"; $totaalPrijs = 0; foreach ($dranken as $DrinkRow) { $aantal = $_POST[ $DrinkRow['name'] . "_aantal"]; if ($aantal > 0) { $prijsperDrank = $aantal * $DrinkRow['price']; echo $DrinkRow['name'] . " : " . $aantal . " Prijs: " . $prijsperDrank . "</br>"; $totaalPrijs=$totaalPrijs + $prijsperDrank; } } if($totaalPrijs>0) { echo " totaal: " .$totaalPrijs; } echo "</table>"; } ?> </body> </html> Hello, I am trying to create a registration module where an email would be sent to the user after registration. I am using xampp and have tried php mailer http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php4/0.90/ but couldn't get it to work... I've been told that it is possible to send an email from localhost through smtp... I need to know how to accomplish that. Am a beginner. suggestions and help would be appreciated I am testing my PHP script with post function to send emails,but the mail is not arriving in my inbox..?What may be the problem..? Hi, I'm trying to create a script that allow me to update my product quantity from external csv file. I've done successfully the first part, update db. But now i want to send one mail with results that are not in db. I check DB from ean, and update product quantity by ean. Sometimes, the csv file have some ean that are not in db, i want to receive one e-mail with this ean's. Here is my code: <?php // Connect to MySQL mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); #if first row of csv file is headings set $row to 1. $row = 1; #database primary table $table_to_update = "table_name"; #get the csv file $handle = fopen("http://www.csvfilewebsite.com/file.csv", "r"); #go through the csv file and print each row with fields to the screen. #and import them into the database updating only the price and quantity while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { if ($c = 1) { $ean13 = $data[($c - 1)]; echo $ean13 . " SKU Assigned <br />\n"; } if ($c = 3) { $quantity = $data[($c - 1)]; mysql_query("UPDATE $table_to_update SET quantity='$quantity' WHERE ean13='$ean13'") or die(mysql_error()); echo $product_quantity . " Imported for row $row in product $ean13 <br />\n"; } // would have to add an additional if statement for each field being updated and know the order of the fields from your csv file //echo $data[$c] . "Imported <br />\n"; } } fclose($handle); echo "<h1>Update Complete.</h1>"; ?> Now, how to check csv ean's that aren't in db, and send mail with this ean's? Hope someone can help me. Regards Mozack hello i`m using this script found on google to send a mail with attachement <?php $strTo = "roccilaura@libero.it"; $strSubject = "Test sending mail."; $strMessage = "My Body & <b>My Description</b>"; //*** Uniqid Session ***// $strSid = md5(uniqid(time())); $strHeader = ""; $strHeader .= "From: Mr.Weerachai Nukitram<email@email.com>\n"; $strHeader .= "Cc: Mr.Surachai Sirisart<email@email.com>\n"; $strHeader .= "Bcc: webmaser@email.com"; $strHeader .= "MIME-Version: 1.0\n"; $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n"; $strHeader .= "This is a multi-part message in MIME format.\n"; $strHeader .= "--".$strSid."\n"; $strHeader .= "Content-type: text/html; charset=windows-874\n"; // or UTF-8 // $strHeader .= "Content-Transfer-Encoding: 7bit\n\n"; $strHeader .= $strMessage."\n\n"; //*** Files 1 ***// $strFilesName1 = "attach.html"; $strContent1 = chunk_split(base64_encode(file_get_contents($strFilesName1))); $strHeader .= "--".$strSid."\n"; $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName1."\"\n"; $strHeader .= "Content-Transfer-Encoding: base64\n"; $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName1."\"\n\n"; $strHeader .= $strContent1."\n\n"; $flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error // if($flgSend) echo "Mail send completed."; else echo "Cannot send mail."; ?> its sends good but one question how can i insert into the attach file values like $name $address directly from a text file Hello friends. First of all note that i'm just an amateur php programmer, so please if what i ask is very dam don't shoot me... I already search the form and found some solutions to send UTF-8 e-mail message using PHP, but for some reason i have to use the above code. The problem is that this code doesn't send UTF-8 e-mail messages. If you can help me please do it. Thank you Code: [Select] <? php $subject = "my subject in UTF-8"; $emailadd = 'mail@mail.com'; $url = "http://www.mySite.com/"; $req = '0'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 40) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 40 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh charset=utf-8 CONTENT="0; URL='.$url.'">'; ?> Hello Im making html mail for my project. However the mail() function of PHP does not send my email. Code: [Select] <?php $message = ' <html> <head> <title>Test Email</title> </head> <body> <h4>This is a test email message from me</h4> <br/> <p><b>Lorem Ipsum<b><br/> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> </body> </html> '; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'To: me <darkstarnexus@yahoo.com>' . "\r\n"; $headers .= 'From: Sample <sample@mail.com>' . "\r\n"; $headers .= 'Cc: Sample2 <sample2@mail>' . "\r\n"; $headers .= 'Bcc: sample3@mail' . "\r\n"; if(mail('darkstarnexus@yahoo.com', 'Test Html Email', $message, $headers)){ echo "mail delivered"; }else{echo "mail is not delivered";} ?> Can some tell me why? |