confused and dazed Posted February 2, 2012 Share Posted February 2, 2012 Hello internet.I am trying to send an e-mail within a script and it does not seem to be working.I echoed the e-mail address and name (in a previous version of the code I posted here) and it recognizes the form data e-mail address and name BUT there is no e-mail that is sent. Any ideas? <?php$con = mysql_connect("xxxx","xxxx","xxxx");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("xxxx", $con);$result = mysql_query("SELECT Member_id FROM selections WHERE name='$_POST[participantname]'", $con); $idnum = mysql_fetch_array($result);$memberid = $idnum['Member_id'];mail("$_POST[participantemail]","Your 2012 Selections","Your Selections have been registered","From:me_yup@hotmail.com"); mysql_close($con)?> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 2, 2012 Share Posted February 2, 2012 How do you know the email doesn't get sent? Could the problem be that it just doesn't get received? Link to comment Share on other sites More sharing options...
confused and dazed Posted February 3, 2012 Author Share Posted February 3, 2012 Its not getting received. I put my own e-mail address in and I am not receiving it. Link to comment Share on other sites More sharing options...
confused and dazed Posted February 3, 2012 Author Share Posted February 3, 2012 Any suggestions anyone? Link to comment Share on other sites More sharing options...
Err Posted February 3, 2012 Share Posted February 3, 2012 You need to have a mail sever for mail() to work. If you are working on your computer you can install a free mail server, just do a search. If you are working off a hosting site, they most likely only turn on that feature for paying customers. Link to comment Share on other sites More sharing options...
confused and dazed Posted February 3, 2012 Author Share Posted February 3, 2012 I have godaddy and it was working just fine for a while and then all of a sudden BOOM nothing. I changed around some code in that file and thought that was the reason but what I changed really had nothing to do with the email part of the code.I will go to my account in the website and see. Thanks. Link to comment Share on other sites More sharing options...
thescientist Posted February 3, 2012 Share Posted February 3, 2012 if it was working, and then stopped working, wouldn't it have been worth asking your hosting company if something they might have done could have caused the issue? Hosts tends to update PHP/environments. Maybe it's cause your from email is hotmail, and that isn't what the domain of the sending mail domain is. also, have you checked the return value of mail() to make sure it is still working correctly? It returns true or false on execution. That would definitely be my first step towards debugging.http://php.net/manual/en/function.mail.php Link to comment Share on other sites More sharing options...
confused and dazed Posted February 3, 2012 Author Share Posted February 3, 2012 How do you check the return value? Link to comment Share on other sites More sharing options...
thescientist Posted February 3, 2012 Share Posted February 3, 2012 if(mail({.....}){ echo 'success';}else{ echo 'failure';}; //or assign the return value$mailReturnValue = mail({...}); if($mailReturnValue){ echo 'success';}else{ echo 'failure';}; Link to comment Share on other sites More sharing options...
confused and dazed Posted February 4, 2012 Author Share Posted February 4, 2012 O.K. so I did it both ways and it said it was a sucess and i echoed the $mailReturnValue and the result was 1. Not sure how to fix this... Link to comment Share on other sites More sharing options...
thescientist Posted February 4, 2012 Share Posted February 4, 2012 have you tried talking to your host like I suggested? Link to comment Share on other sites More sharing options...
confused and dazed Posted February 4, 2012 Author Share Posted February 4, 2012 Yeah I did - they were not very helpful. My project is complete and the only thing left to do is fix this and its irritating me... Link to comment Share on other sites More sharing options...
confused and dazed Posted February 4, 2012 Author Share Posted February 4, 2012 I have been reading up a little on the matter but I cant seem to understand the php.ini thing...Do I need one of these files to make it work? Link to comment Share on other sites More sharing options...
Err Posted February 5, 2012 Share Posted February 5, 2012 Well, yeah. But your host should already have a php.ini installed for that server. Link to comment Share on other sites More sharing options...
confused and dazed Posted February 5, 2012 Author Share Posted February 5, 2012 What is the php.ini? What does it do? Link to comment Share on other sites More sharing options...
Err Posted February 5, 2012 Share Posted February 5, 2012 It's a settings file for your PHP. What to turn off/on, limits, extensions... you know. Link to comment Share on other sites More sharing options...
thescientist Posted February 5, 2012 Share Posted February 5, 2012 http://php.net/manual/en/ini.core.php Link to comment Share on other sites More sharing options...
confused and dazed Posted February 5, 2012 Author Share Posted February 5, 2012 thescientist - that link pretty much is telling me I have no clue what the ###### is going on.I am so angry right now - godaddy wont do anything because they dont support custom scripting. I tried restoring all my files to a date I know it was working and that still did not do anything.It was working just fine... I deleted a couple files and then gone for good. I tried restoring to that date but still no e-mail is getting sent.I was soooo close. Link to comment Share on other sites More sharing options...
confused and dazed Posted February 5, 2012 Author Share Posted February 5, 2012 OK so let me try a different route... Here is the sample code in w3schools php e-mail section $to = someone@example.com; // I put $_POST[...] here becasue I want the user to specify where the e-mail is going$subject = "Test mail";$message = "Hello! This is a simple email message.";$from = someonelse@example.com; // here I put my myaddress@mydomain$headers = "From:" . $from;mail($to,$subject,$message,$headers);echo "Mail Sent."; O.K. so what file or code needs to accompany this to make an e-mail get sent to the user?GoDaddy is not being helpful - they want me to use thier webformmailer.php but I need to create my own custom forms so this wont work.I started looking at php.ini information (the link thescientist provided above - this is not a slam on you thescientist it is a slam on me) and quite honestly I just cant make sense of it.Can anyone guide my next steps so I can send e-mail?Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 5, 2012 Share Posted February 5, 2012 Verify whether or not the mail service is trashing the email. Try sending to several different domains, check spam folders, etc. Link to comment Share on other sites More sharing options...
confused and dazed Posted February 5, 2012 Author Share Posted February 5, 2012 O.K. so I checked a bunch of domain and this may be the thing...Hotmail, gmail, ymail is not working but my actual domain@mydomain is working. Interesting. How do I get the big domains to work? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 6, 2012 Share Posted February 6, 2012 You'll need to look into their requirements for delivering mail. They may require things like SPF records, domainkeys, or other measures that should be explained in their developer documentation. Link to comment Share on other sites More sharing options...
confused and dazed Posted February 7, 2012 Author Share Posted February 7, 2012 O.K. so I have been doing a little reading up on this and I found this code. I want to run it by w3schools to make sure it is clean before I use it.The point of this code is to send the e-mails from my domain and I do see the code in there that does it (I bolded it). I tried sending e-mails to yahoo, gmail, ymail, hotmail from my domain and it worked just fine. So if this code is clean it appears it will allow me to send e-mails from my domain.Let me know what you think of this code before I use it. <?php$thankyou = "Thnks.html";$full_name = $_POST['Full_Name']; $company_name = $_POST['Company_Name']; $email_from = $_POST['Email_Address'];$telephone = $_POST['Telephone_Number']; $comments = $_POST['Requirements']; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string);} $email_message = "Read Message details below:\r\n";$email_message .= "-----------------------------------------\r\n";$email_message .= "Customer Name: ".clean_string($full_name)."\r\n";$email_message .= "Company Name: ".clean_string($company_name)."\r\n";$email_message .= "Email: ".clean_string($email_from)."\r\n";$email_message .= "Telephone: ".clean_string($telephone)."\r\n";$email_message .= "Requirements: ".clean_string($comments)."\r\n"; require_once "Mail.php";$from = "yourid@yourdomain.com"; \\the mail-iD under your domain$to = "yourgmail@gmail.com"; \\the TO gmail ID$subject = "PHP Enquiry form";$body = $email_message;$host = "mail.yourdomain.com"; \\ your domain mail server$username = "yourid@yourdomain.com"; \\the mail-id under your domain$password = "yourpassword"; \\your password for yourid@mydomain.com$headers = array ('From' => $from, 'To' => $to, 'Reply-To'=> $email_from, 'Subject' => $subject);$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));$mail = $smtp->send($to, $headers, $body);if (PEAR::isError($mail)){echo("<p>" . $mail->getMessage() . "<p>");}else{ header("Location: $thankyou");}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 7, 2012 Share Posted February 7, 2012 It's good to use Pear to actually send email from the server with the domain that you're claiming the email is from, but that doesn't affect things like SPF records and domain keys. Link to comment Share on other sites More sharing options...
confused and dazed Posted February 7, 2012 Author Share Posted February 7, 2012 Couple questions...1. What is "pear"?2. If the mail is sent from my domain shouldn't that be O.K. because my domain is sending e-mails just fine? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.