PHP - Sending To Mysql Database, But Nothing Received
Hi all, I have made some code based on following online youtube video for making a HTML form send to mySQL database via PHP: https://youtu.be/qm4Eih_2p-M The form I am making is hopefully going to help in the Hospital at which I work to speed patient referrals, so I am very keen on making it work. I have made the HTML form and the database, which I do not think are the problem. When I click 'Submit' on my HTML form, then my php file comes up with all the code written, rather than the message: "New referral sent succesfully". Additionally, when I check the database via 'MyPHPAdmin' there is no data added to the database I have made.
I have been using Sublime and have spotted some mistakes here and there, but is there something glaringly obvious that I am doing wrong in my code that is stopping my form being sent to the database? <?php $patientname = | $_POST['patientname']; $hospitalnumber = | $_POST['hospitalnumber']; $DoB = | $_POST['DoB']; $specialty = | $_POST['specialty']; $otherspecialty = | $_POST['otherspecialty']; $admissiondate = | $_POST['admissiondate']; $referring = | $_POST['referring']; $bleep = | $_POST['bleep']; $Admission = | $_POST['Admission']; $Illness = | $_POST['Illness']; $Awareness = | $_POST['Awareness']; $question = | $_POST['question']; $history = | $_POST['history']; $medications = | $_POST['medications']; $examination = | $_POST['examination']; $results = | $_POST['results']; $diagnosis = | $_POST['diagnosis']; $investigations = | $_POST['investigations']; $host = "localhost" $dbUsername = "root"; $dbPassword = "xyzabc"; $dbname = "GreenCard"; $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname); if (mysqli_connect_error()) { die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error()); } else { $INSERT = "INSERT Into Greencard (patientname, hospitalnumber, DoB, specialty, otherspecialty, admissiondate, referring, bleep, Admission, Illness, Awareness, question, history, medications, examination, results, diagnosis, investigations) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; //Prepare statement $stmt = $conn->prepare($INSERT); $stmt->bind_param("sisissssssssssssss", $patientname, $hospitalnumber, $DoB, $specialty, $otherspecialty, $admissiondate, $referring, $bleep, $Admission, $Illness, $Awareness, $question, $history, $medications, $examination, $results, $diagnosis, $investigations); $stmt->execute(); echo "New referral sent successfully"; } $stmt->close(); $conn->close(); } else { echo "Make sure fields are completed"; die(); } ?>
Similar TutorialsI really need some help. I am very new to PHP and I've been stuck for a couple of days. I created a contact form and everything seems to be working correctly, except the mail is showing it's sent, but I never receive an email in my Inbox or Spam folder. Can someone please review my code? Here is the PHP: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varpositionErr = ""; $varfname = $varlname = $varemail = $varphone = $varposition = $success = ""; //FORM SUBMITTED WITH POST METHOD if ($_SERVER["REQUEST_METHOD"] == "POST") { //VALIDATE FIRST NAME if (empty($_POST["varfname"])) { $varfnameErr = "First Name is required"; } else { $varfname = test_input($_POST["varfname"]); // MAKE SURE FIRST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varfname)) { $varfnameErr = "Only letters and white space are allowed"; } } //VALIDATE LAST NAME if (empty($_POST["varlname"])) { $varlnameErr = "Last Name is required"; } else { $varlname = test_input($_POST["varlname"]); // MAKE SURE LAST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varlname)) { $varlnameErr = "Only letters and white space are allowed"; } } //VALIDATE EMAIL ADDRESS if (empty($_POST["varemail"])) { $varemailErr = "Email Address is required"; } else { $varemail = test_input($_POST["varemail"]); // MAKE SURE EMAIL ADDRESS IS FORMATTED CORRECTLY if (!filter_var($varemail, FILTER_VALIDATE_EMAIL)) { $varemailErr = "Invalid email address format"; } } //VALIDATE PHONE NUMBER if (empty($_POST["varphone"])) { $varphoneErr = "Phone number is required"; } else { $varphone = test_input($_POST["varphone"]); // MAKE SURE PHONE NUMBER IS IN CORRECT FORMAT if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$varphone)) { $varphoneErr = "Invalid telephone format"; } } //VALIDATE POSITION if (empty($_POST["varposition"])) { $varpositionErr = "Position is required"; } else { $varposition = test_input($_POST["varposition"]); } //IF ALL DATA IS CORRECT if ($varfnameErr == '' and $varlnameErr == '' and $varemailErr == '' and $varphoneErr == '' and $varpositionErr == '') { $message_body = ''; unset($_POST['submit']); //THIS IS JUST FOR TESTING PURPOSES $message_body = $varfname; //foreach ($_POST as $key => $value) { // $message_body .= "$key: $value\n"; //} $to = 'mygmail@gmail.com'; $subject = 'Volunteer Form Submission'; $message = wordwrap($message_body, 70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: " . $varemail . "\r\n"; $subject = 'Volunteer Form Submission'; $to = 'mygmail@gmail.com'; $result = mail($to, $subject, $message, $headers); //THIS RETURNS "1" print $result; //IF ALL DATA IS CORRECT MAKE SURE EMAIL WAS SENT if (mail($to, $subject, $message, $headers)) { $success = "Message sent. Thank you contacting us! We will reply as soon as possible."; $varfname = $varlname = $varemail = $varphone = $varposition = ""; } else { $success = "Something went wrong!"; } } } //STRIP UNWANTED CHARACTERS FROM VARIABLES function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>
Here is the HTML: <div class="row regformrow"> <div class="coffee-span-12 regformcolumn"> <div class="subgrid regformsubgrid"> <div class="row regformsubgridheaderrow"> <div class="coffee-span-12 regformsubgridheadercolumn"> <h4 class="regformsubgridheadertitle">Volunteer Form</h4> </div> </div> <div class="row regformsubgridrow"> <form class="form-container regformsubgridformcontainer" action=<?= $_SERVER['PHP_SELF']; ?> method="post"> <div class="coffee-span-4 coffee-972-span-6 coffee-458-span-12 regformsubgridcolumn1"> <div class="container regformsubgridcontainer1"> <label class="label form-label-all"><span style="font-style:italic;color:#FF5454;">* Required Fields</span></label></br> <div class="formfieldgroup"> <input class="fname" name="varfname" type="text" tabindex="1" placeholder="First Name" value="<?= $varfname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varfnameErr ?></span> </div> <div class="formfieldgroup"> <input class="lname" name="varlname" type="text" tabindex="2" placeholder="Last Name" value="<?= $varlname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varlnameErr ?></span> </div> <div class="formfieldgroup"> <input class="email" name="varemail" type="text" tabindex="2" placeholder="Email Address" value="<?= $varemail; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varemailErr ?></span> </div> <div class="formfieldgroup"> <input class="phone" name="varphone" type="text" tabindex="2" placeholder="Telephone Number" value="<?= $varphone; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varphoneErr ?></span> </div> <div class="formfieldgroup"> <select class="select selectbox" name="varposition" id="varposition" tabindex="5"><option value="">Select one...</option><option value="Chaperone">Chaperone</option><option value="Class Monitor">Class Monitor</option><option value="Parking Attendant">Parking Attendant</option><option value="Party Coordinator">Party Coordinator</option><option value="Teacher Aid">Teacher Aid</option></select><span class="requiredfield"> *</span> <span class="form-error"><?= $varpositionErr ?></span> </div> <div class="formfieldgroup"> <input class="test" name="test" type="text" tabindex="6" placeholder="If you are human, leave this field blank" value=""> </div> <div class="formfieldgroup"> <button type="submit" class="button-submit-1" name="submit" tabindex="7" data-submit="...Sendng">Submit</button> </div> <div class="formfieldgroup"> <div class="success"><?= $success; ?></div> </div> </div> </div> </form> </div> </div> </div> </div> Edited February 20, 2020 by mike3075 Hi folks, I just found this group and joined up! I have encountered a problem that I am not sure how to resolve, and I hope someone can assist. I run this query against my MySQL database: mysql_select_db($database_commdb, $commdb); $query_rsEmailAddress = "SELECT admin_email FROM tbl_admins WHERE admin_id = 1"; $rsEmailAddress = mysql_query($query_rsEmailAddress, $commdb) or die(mysql_error()); $row_rsEmailAddress = mysql_fetch_assoc($rsEmailAddress); $totalRows_rsEmailAddress = mysql_num_rows($rsEmailAddress); ...and want to use the result to populate the "mail to" field for my response form. (I'm doing this to avoid having my email address posted in a page to be skimmed.) I presently use this: $to = rsEmailAddress['admin_email']; I do some empty fields checking before submitting the form. However, when I click on submit, my form, tells me I have empty fields and will not process when there are NO empty fields. HOWEVER, if I hard-code my email address in the variable "$to" all is well, the form processes correctly, I get the email, etc... So I suspect the problem lies somewhere in the way I have constructed the $to variable. I have scratched my head till I am going bald(er) and my scalp is bleeding!!! HELP!! Please!! Hi there, I am using this code to send the users email address to the database. That works fine, but i keep getting blank info added to the database. Does anyone know how i can stop this? <?php $con = mysql_connect("*","*","*"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ogs_mailinglist1", $con); $sql="INSERT INTO mailinglist (email) VALUES ('$_POST[rec_email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?> Thanks, I have no idea what im doing wrong but this just isnt working, theres no error messages but im not getting any of the emails. Here is all the code that i had anything to do with editing, i have removed any personal info from it. Code: [Select] <?php $dbhost = 'localhost'; $dbuser = ' '; $dbpass = ' '; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db(" ", $conn); $result = mysql_query("SELECT ****, ********** FROM **** WHERE name='*****'"); while($row = mysql_fetch_array($result)) { $message = "<p><u><b><font size=\"5\" color=\"#800080\">********************</font></b></u></p> <p><b><font color=\"#800080\" size=\"4\">**************************************************</font></b></p> <p><b><font color=\"#800080\">*********</font></b> <b><font color=\"#333333\">**********</font></b></p> <p><b><font color=\"#800080\">********</font></b> <font color=\"#333333\"><b>***********</b></font></p> <p><font color=\"#800080\"><b>*******</b></font> <font color=\"#333333\"><a href=\"***********************************************</a></font></p> <p> </p>"; } $query=mysql_query('SELECT `email`,`name` FROM `users`'); //grab emails and names from database while($row = mysql_fetch_array($query)) //start a loop to send an email to each individual { //mail function with $row['email'] as the email address //I'm using phpmailer as an example here - - > include_once('phpMailer/class.phpmailer.php'); $mail = new PHPMailer(); // defaults to using php "mail()" $body = $message; //message inside the email $mail->From = "**************"; //email address that the email is being sent from $mail->FromName = "*************"; //more in depth for who the mail is from. $mail->Subject = "***********************************"; //The subject for the message //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->AddAddress($row[email], $row['name']); } mysql_close($conn); ?> Hi All, Is there a way we can write a PHP script to automatically read receive emails, extract csv file attachment from there and insert into MySQL database then run this in Cron Jobs to automate the process? Hi All, Is there a way we can write a PHP script to automatically read receive emails, extract csv file attachment from there and insert into MySQL database then run this in Cron Jobs to automate the process? 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 Hi Everyone, Very new to PHP and databases, so please go easy on me! I have a series on web pages each containing a link that says 'apply here'. What I am trying to achieve is when any of these links are clicked on the user is taken to a php form page where they are asked for a series of further information such as name, telephone number etc. When they click submit this information then gets sent off to a speciifc email address. My problem is that depending on which page the user has originally come from (the page where they clicked on the apply here link) needs to determine what email address the form information gets sent to. I thought that the best way to achieve this would be to create a database that contains all of the email addresses (as eventually there will be alot of them) and the form page could call in the relevant email somehow... although I am totally confused on how to go about doing this. Any help would be great! Thankyou. fixed. Hi, I have a project where i want to send the sms to the customers at the particular time calling from the database, how to do these in php? Thanks, I have a PHP Form where users have to enter and upload a file but when they click upload everything is working except that it is only sending first character of text field to Database! Can any one help?? Thanks File upload.php form Code: [Select] <form action="add_file.php" method="post" enctype="multipart/form-data"> <p><br> JobID: <input name="JobID" type="text" value="<?php echo $row_Recordset1['JobID']; ?>" readonly="readonly" /> </p> <p>Company ID: <input name="CompanyID" type="text" value="<?php echo $row_Recordset1['CompanyID']; ?>" readonly="readonly" /> </p> <p>UserID: <input name="UsersID" type="text" /> </p> <p>Select File to upload: <input type="file" name="uploaded_file" /> </p> <p>Make Sure All Details Are Correct before Submitting!</p> <p> <input type="submit" value="Submit Application" /> </p> <form> add_file.php // Check if a file has been uploaded if(isset($_FILES['uploaded_file'])) { // Make sure the file was sent without errors if($_FILES['uploaded_file']['error'] == 0) { // Connect to the database $dbLink = new mysqli('localhost', 'user', 'password', 'phpsite'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Gather all required data $JobID = $dbLink->real_escape_string($_POST['JobID']['JobID']); $CompanyID = $dbLink->real_escape_string($_POST['CompanyID']['CompanyID']); $UsersID = $dbLink->real_escape_string($_POST['UsersID']['UsersID']); $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']); $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']); $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name'])); $size = intval($_FILES['uploaded_file']['size']); // Create the SQL query $query = " INSERT INTO `application` ( `JobID`, `CompanyID`, `UsersID`, `name`, `mime`, `size`, `data`, `N_DateAndTime` ) VALUES ( '{$JobID}', '{$CompanyID}', '{$UsersID}', '{$name}', '{$mime}', {$size}, '{$data}', NOW() )"; // Execute the query $result = $dbLink->query($query); // Check if it was successfull if($result) { echo 'Success! Your job application was successfully sent!'; } else { echo 'Error! Failed to insert the file, please try again' . "<pre>{$dbLink->error}</pre>"; } } else { echo 'An error accured while the file was being uploaded, please try again. ' . 'Error code: '. intval($_FILES['uploaded_file']['error']); } // Close the mysql connection $dbLink->close(); } else { echo 'Error! A file was not sent! Please try again!'; } // Echo a link back to the main page echo '<p>Click <a href="year1index.php">here</a> to go back</p>'; ?> MOD EDIT: [code] . . . [/code] BBCode tags added. Here is a link to screenshots of what is happening, because I'm crappy at describing things: http://imgur.com/a/ahvPA Of course I've messed the code up somewhere, but I can't for the life of me figure out where. I have a simple page for someone to enter text in a textbox to save in a database to display on another page. There are 10 textboxes on the page. I can enter text into any and all textboxes and it'll save the data in the database, EXCEPT if I enter text into the 2nd textbox. If there's anything in the 2nd textbox after I click submit, it will delete whatever was in the 2nd textbox and move all data in each textbox (except textbox 1, which stays in the same place) down one element. And it pushes the data in the final textbox off the page (presumably because there's no other textbox to accept its data). Here is the code to the two pages affected. Any help would be appreciated! Code: [Select] <?php // start the session session_start(); if (!session_is_registered($_SESSION['myusername'])) { header ('location:./login.php'); } $i=1; require_once('./dbconnect.php'); $sql="SELECT `event` FROM `events`"; $result=mysql_query($sql); mysql_close(); ?> <!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> <title>Admin Portal</title> </head> <body> <form name="events" method="post" action="eventlogging.php"> <table width="800" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td> <table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td colspan="3" bgcolor="#CCCCCC"> <strong><p><strong>Admin Portal</strong></p><p align="right"><small><a href="./logout.php">Logout</a></small> </td> </tr> <?php while ($i<11) { echo ' <tr align="center"> <td align="right" width="100">Event ' . $i . ' </td> <td width="800"> <textarea name=event' . $i . ' cols=40 rows=5>'; $row = mysql_fetch_array($result); if ($row) { $msg=$row[0]; echo $msg; }; $i++; echo '</textarea> </td> </tr> '; } ?> <tr> <td colspan="2"> <center><input type="submit" name="Submit" value="Submit" /></center> <input type="hidden" name="submitted" value="true" /> </td> </tr> </td> </tr> </table> </td> </tr> </table> </form> </body> </html> <?php $position = 1; $dbControl = 9; $event = array(); if (!empty($_POST['event1'])) { $event[] = $_POST['event1']; } if (!empty($_POST['event2'])) { $event[] = $_POST['event']; } if (!empty($_POST['event2'])) { $event[] = $_POST['event']; } if (!empty($_POST['event3'])) { $event[] = $_POST['event3']; } if (!empty($_POST['event4'])) { $event[] = $_POST['event4']; } if (!empty($_POST['event5'])) { $event[] = $_POST['event5']; } if (!empty($_POST['event6'])) { $event[] = $_POST['event6']; } if (!empty($_POST['event7'])) { $event[] = $_POST['event7']; } if (!empty($_POST['event8'])) { $event[] = $_POST['event8']; } if (!empty($_POST['event9'])) { $event[] = $_POST['event9']; } if (!empty($_POST['event10'])) { $event[] = $_POST['event10']; } include ('./dbconnect.php'); mysql_query("DELETE FROM `events`"); foreach ($event as $msg) { mysql_query("INSERT INTO `events` (`position`, `event`, `date`) VALUES ('$position', '$msg', curdate() )") or die(mysql_error()); $position++; } mysql_close(); $position=1; /* foreach ($event as $msg) { echo $position . '. ' . $msg . '<br />'; $position++; } */ header("location:./admin.php"); ?> I have an HTML form that I have a "select" drop-down menu that is selecting the name of the person you should send to. The names are being pulled from the Database, and here is what that code for the drop-down in the form looks like: <?php echo '<select name= "First_Name" , "Last_Name">'; while( $array = mysql_fetch_assoc($result) ) { $text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"]; $value_for_select = $array["First_Name"] . " " . $array["Last_Name"] . "_" . $array["id"]; echo "<option></option>\n"; echo "<option value=\"$value_for_select\">$text_for_select</option>\n"; } echo '</select>';?> This works perfectly. However, what I want it to do is send the form to the email address of the person that is selected in the drop-down. The email address' are already entered in each record of the database in a field called "Email". I am using the $value_for_select variable to pull the id of the record, but I am unsure how to then tell the form to send to the email address of that record? Anybody know a way that this can be done? Here is the code of the for that should be sent: <?php if($_POST){ $to = $email; $subject = "WHAT SHOULD THIS BE"; $message = "Date: $date\n\r". "Dear $First_Name, $Last_Name,\n\r". "Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah..\n\r". "Sincerely,\n". "$name \n". "$street \n". "$city, $zip \n". "$email \\n". $headers = "From: $email"; mail($to, $subject, $message, $headers); // SUCCESS! echo '<p class="notice">'. 'Thank you for your submission. '. '</p>'; // clear out the variables for good-housekeeping unset($date,$legislator,$bill,$name,$street,$city,$zip,$email); $_POST = array(); } ?> Please help! Basically what I am needing is when a visitor comes to my site and request info on a product, the form sends the product id or name.
I have the site set up like product.php?Item=26 and the item number changes based on the product. The page items are being populated with info stored in the mysql databse.
I need the email being sent to say something like
Visitors Name has requested info on Item 26 Name - Visitors Name Email - email@me.com Phone - 123-456-7890 Company - Visitors Company Item info requested for Here is the products name URL to product page Basically the "item info" is being pulled from the database. I have asked on different forums and I cannot get a good answer that I can use to make this happen. I might not be explaining it right. Page the form is on is (and all other new-product.php pages) http://www.packagingequipment4sale.com/new-product.php?Item=26Any help would be greatly appreciated At the moment I am creating a search function for my website. The approach I have in mind is a pseudo-PHP database. To give an example: A HTML form will submit the results to a PHP file. HTML FORM - Colour: Black PHP RESULT PAGE - if ($_POST['color'] == 'Black') {readfile("./products/black/*.html");} HTML FORM - Price: <$50 PHP RESULT PAGE - if ($_POST['Price'] == '<$50') {readfile("./products/less50/*.html");} The problem here is if there is an item that is black and costs less than $50, then its going to be listed twice. There is probably some code I can write to ommit the listing of duplicate entries, but it is probably going to be messy, so I am wondering if its better to use a centralized MySQL database, rather than a pseudo-PHP database? I've never used MySQL and don't know much about it and this is my first real attempt at using PHP. Hi guys ,
I am facing issues with php mails. I have iis and SMTP configured on the sever . Mail send and receive was working properly. But suddenly not able to receive email. I have tried simple php email script . it shows email sent but not received. I have tried php mailer also but same happened. Please reply if somebody could help me out. i need to resolve this issue as soon as possible. I have iis 6 and windows 2012 and php 5.5
Edited by Poonam, 21 August 2014 - 08:36 AM. Hello once again Php Freaks! I've probably posted this problem a few times a year for the past 5 or so years. I am a dev/admin for the site marcomtechnologies.com. From that website, using php we send emails out. Some users never get the email and it isn't in their spam folder. The two users we can confirm never get the email have @att.net email address and, let me warn you. Do not ever, EVER call att/yahoo/sbc for tech support. It's an endless circle and when you do finally talk to someone, they have a really hard time grasping that it is about emails coming from a server they are not hosting.
I've talked to GoDaddy everytime, and everytime it is the same thing. Everything is ok on their end.
I will post the code below. First what I have done.
- The emails are coming "FROM" the correct domain. The website is marcomtechnologies.com, and the emails are from admin@marcomtechnologies.com. This was something that if not set this way, would be flagged as spam right off the top. this is a valid email, on the email services provided by godaddy. I can log in and send and receive emails from there no problem.
- I was using the standard PHP mail command, than switched to PHPMailer and we still have the same problem.
- I have checked to see if the domain is blacklisted. As far as I can tell it is not. If it was true, than my address, @gmail wouldn't get the emails and I do. (quick note, a few weeks ago even I didn't get some?)
- GoDaddy tells me that we have 250 "relays" or emails that can go out. On a daily basis, we may send 50 messages. If that.
- I have tried to get bounce back messages stating the message was undelivered and have yet to ever get one.
- We have set up read receipts and they work, but not every sales person reads their emails, just kinda ignores them. So read receipts are not really helping us, cause we don't know if they are ignoring the message, or not getting them.
- For one of our customers, we had to talk to an admin and have them put a rule on there server allowing messages from our domain. From what we can tell it worked, but again are the sales staff ignoring, or not getting the message? We don't know until we are there and they say so. Why is att.net not getting them?
The emails are going out and leaving godaddy. Somewhere between godaddy and the receiver, the message is blocked, lost, deleted or just decides to take a day off. Which is really what seems to be happening. I've reach a state of utter frustration with this. Emails are a simple, all over the place, everyone uses, and has for a long long time technology. What can I do to confirm they got the message without them having to actually read it? What can I do to determine why the message isn't making it? I'm never getting those bounce backs, so I have no details at all.
The clients we serve are not the most tech capable, and for all we know everything is ok. the problem is, for my boss, this is unacceptable. I need a solution, and a confirmation that the solution is working 110%.
What am I missing? Here is the chuck of code that sends the messages out :
require 'PHPMailer/PHPMailerAutoload.php'; require_once('PHPMailer/class.phpmailer.php'); $results_messages = array(); $mail = new PHPMailer(true); $mail->CharSet = 'utf-8'; class phpmailerAppException extends phpmailerException {} if($file_name[0]=='') { try { if(!PHPMailer::validateAddress($to)) { throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!"); } $body = $email_message; $body = eregi_replace("[\]",'',$body); $mail->AddReplyTo($_SESSION['member_email'],$_SESSION['WholeName']); $mail->SetFrom("admin@marcomtechnologies.com",$_SESSION['WholeName']); $mail->AddAddress($to,$to); $mail->Subject = $MSG_row['msg_subject']; $mail->MsgHTML($body); if(!$mail->Send()) { $results_messages[] = "Mailer Error: " . $mail->ErrorInfo; } else { $results_messages[] = "Message has been sent to " . $to . ', '; } } catch (phpmailerAppException $e) { $results_messages[] = $e->errorMessage(); } } else { $path = '../audio_upload/' . $audio_filename; $path_name=$audio_filename; try { if(!PHPMailer::validateAddress($to)) { throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!"); } $mail->isSendmail(); $mail->addReplyTo($_SESSION['member_email'], $_SESSION['WholeName']); $mail->SetFrom("admin@marcomtechnologies.com",$_SESSION['WholeName']); $mail->addAddress($to, $to); $mail->Subject = $MSG_row['msg_subject']; //$body = "<<<'EOT'"; $body = $email_message; //$body .= "EOT"; $mail->WordWrap = 80; $mail->msgHTML($body, dirname(__FILE__), true); //Create message bodies and embed images // preparing attachments $main_path='email_upload/'; for($x=0;$x<count($file_name);$x++){ $mail->addAttachment($main_path.$file_name[$x]); // optional name } try { $mail->send(); $results_messages[] = "Message has been sent to " . $to . ', '; } catch (phpmailerException $e) { throw new phpmailerAppException('Unable to send to: ' . $to. ': '.$e->getMessage()); } } catch (phpmailerAppException $e) { $results_messages[] = $e->errorMessage(); } } $mail->clearAddresses(); $mail->clearAttachments();The above is just the part that sends the email, it is part of an AJAX file, and you can download a ZIP with the whole file he http://marcomtechnol.../email_code.zip I have removed the database usernames/password stuff. You will see what I mean, other than that it is 100% complete. I have absolutely no idea what to do. I'm in the dark blindfolded. Thank you so much for taking the time to review my problem! Nick I am using rawurlencode for my urls, like this: I have a site that allows people to register for a fee. It is a very basic form asking for name and contact info.
After they fill out the form and submit it, they are brought to paypal to make their payment. After paying, the form data is sent to the admin and to the customer.
What is very strange is the form seems to work perfectly most of the time, except sometimes:
1. the email is not received by the admin (not sure if the buyer is getting their copy though).
2. if multiple email addresses in the admin settings to receive it (comma separated), sometimes some receive it, but some do not!
The owner of the site said they do check their spam and we've tried different email addresses for the admin (gmail, outlook, yahoo, etc..) and it has occurred on all of them, no rhyme or reason.
Do you see anything wrong with my form below that would have this intermittent issue?
Also, anyone suggest how I can add headers to this so that the 'from' won't default to the host server name?
The file admin.php contains the email variable $admin_email
<?php require '../admin.php'; session_start(); if (!isset($_SESSION['order_id']) || empty($_SESSION['order_id'])) { header('Location: ../../'); } // admin email mail($admin_email, 'Website form submitted', 'Visitor information. Registration: ' . $_SESSION['order_id']."\r\n".' First Name: ' .$_SESSION['fname'].' Last Name: ' .$_SESSION['lname'].' Email: ' .$_SESSION['email'].' Phone: ' .$_SESSION['phone']); // visitor email $to = $_SESSION['email']; mail($to, 'Thank you for registering', 'Review your submission below. Please contact us if you need further assistance. Registration: ' . $_SESSION['order_id']."\r\n".' First Name: ' .$_SESSION['fname'].' Last Name: ' .$_SESSION['lname'].' Email: ' .$_SESSION['email'].' Phone: ' .$_SESSION['phone']); session_destroy(); ?> |