Cetanu Posted July 3, 2009 Share Posted July 3, 2009 Hey, guys. The mail() function will not work for me and I was wondering if anyone could tell me why... contact.php <?php session_start(); ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Contact Us</title> <link rel="stylesheet" type="text/css" href="/style.css" /> <link rel="shortcut icon" href="/fav.png"> <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="style-ie.css" /> <![endif]--> <script type="text/javascript"> function cacherVoir(theDIV){ leStyle = document.getElementById(theDIV).style ; if(leStyle.display == "block") { leStyle.display = "none"; } else{ leStyle.display = "block"; } } </script> <meta name="verify-v1" content="LiYZqvPLQLMOR/3+Stk2cMxWr2l80SisI86GjbuNmLU=" > <style type="text/css"> #header{ margin:0 auto; } #container{ background: #4b4214 url() repeat-y scroll 0 0; overflow:hidden; margin:0 auto; width:82%; } #left-sidebar{ margin-left:0; padding-left:50px; width:150px; float:left; padding-top:20px; } #main-content{ width:62%; margin-left:0; padding-left:80px; float:left; padding-right:0; } #footer{margin:0 auto;} </style> </head> <body> <div id="page-wrap"> <div id="inside"> <div id="header"> <?php include "button.php"; ?> </div> <div style="clear:both;"></div> <div id="container"> <div id="left-sidebar"> <p> <?php include "home.php"; ?><br/> <a href="http://mythscape.freezoka.com/wiki//index.php?MythScapeMainPage" target="_blank">Wiki</a></div> </p> <div id="main-content"> <a href="index.php">Home</a><br/> <form method="post" action="sendeail.php"> <fieldset> <legend>Contact Form</legend> <!-- DO NOT change ANY of the php sections --> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> Your Name: <br /> <input type="text" name="visitor" size="35" /> <br /> Your Email:<br /> <input type="text" name="visitormail" size="35" /> <br /> <br /> <br /> Subject:<br /> <select name="attn" size="1"> <option value=" Help ">Help </option> <option value=" Comments ">Comments </option> <option value=" Feedback ">Feedback </option> <option value=" Suggestions ">Suggestions </option> <option value=" General Question ">General Question </option> <option value=" Unspecified ">Other </option> </select> <br /><br /> Content <br /> <textarea name="notes" rows="4" cols="40"></textarea> <br /> <input type="submit" value="Submit" /> </fieldset></form> <br /> </div> </div> <div style="clear: both;"></div> <?php include "footer.php"; ?></p> </div></div> <div style="clear: both;"></div> </div> </body> </html> sendeail.php <?php session_start(); ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Send Email</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="shortcut icon" href="fav.png"> <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="style-ie.css" /> <![endif]--> <script type="text/javascript"> function cacherVoir(theDIV){ leStyle = document.getElementById(theDIV).style ; if(leStyle.display == "block") { leStyle.display = "none"; } else{ leStyle.display = "block"; } } </script> <meta name="verify-v1" content="LiYZqvPLQLMOR/3+Stk2cMxWr2l80SisI86GjbuNmLU=" > <style type="text/css"> #header{ margin:0 auto; } #container{ background: #4b4214 url() repeat-y scroll 0 0; overflow:hidden; margin:0 auto; width:82%; } #left-sidebar{ margin-left:0; padding-left:50px; width:150px; float:left; padding-top:20px; } #main-content{ width:62%; margin-left:0; padding-left:80px; float:left; padding-right:0; } #footer{margin:0 auto;} </style> </head> <body> <div id="page-wrap"> <div id="inside"> <div id="header"> <?php include "button.php"; ?> </div> <div style="clear:both;"></div> <div id="container"> <div id="left-sidebar"> <p><?php include "home.php"; ?><br/> <a href="http://mythscape.freezoka.com/wiki//index.php?MythScapeMainPage" target="_blank">Wiki</a></div> </p> <div id="main-content"><?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $notes = $_POST['notes']; $attn = $_POST['attn']; if (eregi('http:', $notes)) { die ("Do NOT try that! ! "); } if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) { echo "<h2><a href='contact.php'>Enter valid e-mail</a></h2>\n"; $badinput = "<h2>Query was NOT submitted</h2>\n"; echo $badinput; die (""); } if(empty($visitor) || empty($visitormail) || empty($notes )) { echo "<h2><a href='contact.php'>Fill in all fields!</a></h2>\n"; die (""); } $todayis = date("l, F j, Y, g:i a") ; $attn = $attn ; $subject = $attn; $notes = stripcslashes($notes); $message = " $todayis [EST] \n Attention: $attn \n Message: $notes \n From: $visitor ($visitormail)\n Additional Info : IP = $ip \n Browser Info: $httpagent \n Referral : $httpref \n "; $from = "From: $visitormail\r\n"; mail("predhead9@yahoo.com", $subject, $message, $from); ?> <p align="center"> Date: <?php echo $todayis ?> <br /> Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) <br /> Subject: <?php echo $attn ?> <br /> Message:<br /> <?php $notesout = str_replace("\r", "<br/>", $notes); echo $notesout; ?> <br /> <?php echo $ip ?> <br /><br /> <a href="contact.php"> Send Another </a> | <a href="index.php">Home</a> </p> </div> </div> <div style="clear: both;"></div> <div id="footer"> <p><?php include "footer.php"; ?></p> </div></div> <div style="clear: both;"></div> </div> </body> </html> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/ Share on other sites More sharing options...
ldougherty Posted July 3, 2009 Share Posted July 3, 2009 What happens when you try and send the email? Are you receiving any errors? Without knowing how the script executes there is no way to know off hand what issue you may he experiencing since there are a thousand things that can go wrong with email. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868599 Share on other sites More sharing options...
Cetanu Posted July 4, 2009 Author Share Posted July 4, 2009 I don't receive emails in my account. I tried to email addresses and neither received the test emails I sent. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868602 Share on other sites More sharing options...
Cetanu Posted July 4, 2009 Author Share Posted July 4, 2009 Anyone have any clues maybe as to why? Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868812 Share on other sites More sharing options...
mattal999 Posted July 4, 2009 Share Posted July 4, 2009 Try changing: mail("predhead9@yahoo.com", $subject, $message, $from); To: if(mail("predhead9@yahoo.com", $subject, $message, $from)) { echo "Mail sent"; } else { echo "Could not send mail."; } And see what it outputs. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868818 Share on other sites More sharing options...
ldougherty Posted July 4, 2009 Share Posted July 4, 2009 Also try changing the TO address from Yahoo to something else like a Gmail account. Yahoo is notorious for grey listing emails based on IP reputation. Therefore even if your script works properly Yahoo could be blocking your mail. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868825 Share on other sites More sharing options...
Cetanu Posted July 4, 2009 Author Share Posted July 4, 2009 I did that. No luck. The emails never even showed up in my Yahoo or my GMail. EDIT: The change in the PHP echoed "Mail Sent", which is good, let's see if I can get it. EDIT #2: I didn't get it, this time I tried Yahoo, GMail, and my School Email Address. No luck. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868836 Share on other sites More sharing options...
ldougherty Posted July 4, 2009 Share Posted July 4, 2009 Do you have access to the mail logs on your server?? If the script is saying its sent then it's being blocked somewhere. If you do not have access to the mail logs ask your web host to take a look at the mail log to determine if the message is successfully leaving their network or not. If it is then the issue is with the recipient mail server, probably your junk mail folder. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868839 Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 don't forget to check the junk mail folder! Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868851 Share on other sites More sharing options...
mattal999 Posted July 4, 2009 Share Posted July 4, 2009 I have this problem with freehosts all the time. I know for a fact that freehostia blocks all email sending from freehosted websites, even though the mail() command returns true. If you are using shared hosting of any kind, ask their tech support if they block this kind of thing. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868870 Share on other sites More sharing options...
Adika Posted July 4, 2009 Share Posted July 4, 2009 The problem must be in your From header. Try using this From header: "From: ".$visitormail."<mysitemail@yahoo.com>". "\r\n"; instead of this one that you used: "From: $visitormail\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868872 Share on other sites More sharing options...
Cetanu Posted July 4, 2009 Author Share Posted July 4, 2009 I checked my Spam folders, but it wasn't there. :-\ I am using a free webhost, maybe that's the problem, if that's the case, that is bad. But I checked something a while back that said emails were allowed...maybe I was looking at the wrong thing. I'll try and contact the host, and I'll try to change the header. Thanks, guys. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868940 Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 Try using fsockets instead of mail, (you can use PHPMailer) this allows you to use authenticated accounts, as non-authenticated are have a higher spam class Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-868942 Share on other sites More sharing options...
Cetanu Posted July 5, 2009 Author Share Posted July 5, 2009 Okay, I'll try this, then. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-869047 Share on other sites More sharing options...
haku Posted July 5, 2009 Share Posted July 5, 2009 The email account may need to exist before you can send mail from it - many hosts make this a requirement. Does the account exist? Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-869140 Share on other sites More sharing options...
Cetanu Posted July 5, 2009 Author Share Posted July 5, 2009 Yep. I think it's because I am using the host's free webhosting plan, but they will only allow mail to escape the site if I upgrade. I'm not sure because I've tried 4 different emails now and none work. Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-869206 Share on other sites More sharing options...
MadTechie Posted July 5, 2009 Share Posted July 5, 2009 A simple solution would be to create a gmail email account, and use PHPMailer Quote Link to comment https://forums.phpfreaks.com/topic/164697-mail-not-working/#findComment-869230 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.