PadLock Posted June 9, 2012 Share Posted June 9, 2012 Problem Background: The PHP code I am working with spans three pages. It starts on the first gathering information in a form. On the second it checks to make sure all fields were entered and that the data inside them is valid. On this second page these values are set to cookies and we are taken to a third page if there are no errors where the information is mailed to my client. The third page is where I am having my problems. Problem: Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/31/9395831/html/PHP/Z4L_Snd.php on line 36 Line 36 consists of mail($to, $subject, $message, $headers); This is the code for the third page which is getting the error in its entirety. <!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 $td = date("Y-m-d"); $today = "Date :" . $td; $fname = "\n" . "First Name : " . $_COOKIE["fName"] . "\n"; $lname = "Last Name : " . $_COOKIE["lName"] . "\n"; $email = "Email : " . $_COOKIE["email"] . "\n"; $hphone = "Home Phone : " . $_COOKIE["Hphone"] . "\n"; $mphone = "Mobile Phone : " . $_COOKIE["Mphone"] . "\n"; $contact = "Preferred Contact: " . $_COOKIE["contact"] . "\n"; $to = "client email address"; $subject = "Contact Information: " . $fname . " " . $lname; $message = $today . $fname . $lname . $email . $hphone . $mphone . $contact; $from = "client info email address is here"; $headers = "From:" . $from; mail($to, $subject, $message, $headers); echo "Mail Sent."; ?> </body> </html> Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/263911-mail-not-sending-via-mail/ Share on other sites More sharing options...
insidus Posted June 9, 2012 Share Posted June 9, 2012 I take it that $to and $from are actual emails address? e.g $to = "[email protected]"; If so, try running a telnet to see if you can actually send an email Quote Link to comment https://forums.phpfreaks.com/topic/263911-mail-not-sending-via-mail/#findComment-1352480 Share on other sites More sharing options...
PadLock Posted June 9, 2012 Author Share Posted June 9, 2012 I take it that $to and $from are actual emails address? e.g $to = "[email protected]"; If so, try running a telnet to see if you can actually send an email Yes they are actual emails. The site is hosted on GoDaddy and the original form I made that just sends the email without checking for errors works so I know that emails can in fact be sent which is what puzzles me about this. I should also add that the $from email that is going in $headers is of the same domain as the website so that shouldn't be the issue either. Quote Link to comment https://forums.phpfreaks.com/topic/263911-mail-not-sending-via-mail/#findComment-1352500 Share on other sites More sharing options...
insidus Posted June 10, 2012 Share Posted June 10, 2012 if it sent before when you wasn't checking for errors, then the problems resides outside of the mail function, surely? try echo "mail($to, $subject, $message, $headers)"; That will show you how the 'mail' looks when you are sending it, see if they are any errors. You can also try mail("add_the_email_here", "this is a test", "this is a test message, did you receive this?", "from: [email protected]"); I also found this :http://drupal.org/node/196792 which blames goDaddy for the same problems, so maybe its with goDaddy? /insidus Quote Link to comment https://forums.phpfreaks.com/topic/263911-mail-not-sending-via-mail/#findComment-1352609 Share on other sites More sharing options...
darkfreaks Posted June 11, 2012 Share Posted June 11, 2012 that issue was patched by drupal by removing all non-english characters from the email field. Quote Link to comment https://forums.phpfreaks.com/topic/263911-mail-not-sending-via-mail/#findComment-1352835 Share on other sites More sharing options...
PadLock Posted June 11, 2012 Author Share Posted June 11, 2012 I fixed the problem. It seems that defining the subject or the body of the email with the variables above which consisted of other predefined variables from the cookies was the problem. The original mail() code was: mail($to, $subject, $message, $headers); What I wound up doing was: mail($to, "New Contact Information", $today.$fname.$lname.$email.$hphone.$mphone.$contact, $headers); This seems to be working. I'm not sure if it is because I am getting the variable definitions from cookies or what the issue was but this seemed to fix it. If anyone happens to know exactly what caused the issue I would love to know so I can work around it more intelligently in the future. Quote Link to comment https://forums.phpfreaks.com/topic/263911-mail-not-sending-via-mail/#findComment-1352962 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.