i have an email script on my page and when i send it, i never receive the emails on the other. I can't figure out why it isn't sending, I'm sure there is something small wrong in the code that I can't catch since I don't know what to look for. Anyone got any ideas? Any help is appreciated Contact.php ------> the page that contains the email form. here is the coding <form method="post" action="sendemail.php"> <?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 ?>" /> Department:<br /> <select name="attn" size="1"> <option value=" Sales ">Sales</option> <option value=" Customer Service ">Customer Service</option> <option value=" Webmaster ">Webmaster </option> </select> <br /><br /> Your Full Name: <br /> <input type="text" name="visitor" size="35" /> <br /> Your Email:<br /> <input type="text" name="visitormail" size="35" /> <br /> <br /> How can we assist you? <br /> <textarea name="notes" rows="10" cols="40"></textarea> <br /> <input type="submit" value="Send Mail" /> </form> sendemail.php---------->the php script that should send the email <?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>Use Back - Enter valid e-mail</h2>\n"; $badinput = "<h2>Feedback was NOT submitted</h2>\n"; echo $badinput; die ("Go back! ! "); } if(empty($visitor) || empty($visitormail) || empty($notes )) { echo "<h2>Use Back - fill in all fields</h2>\n"; die ("Use back! ! "); } $todayis = date("l, F j, Y, g:i a") ; $attn = $attn ; $subject = 'ToTheLetter Customer Service Request'; $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 ('sales@2theletter.net', $subject, $message, $from); ?>
You shouldnt be posting over the IP and user agent of the user, just move those variables to the php script so that they are fresh and cannot be tampered with by the user. Are you sure mail is setup on your server? As some servers/web hosts wont allow mail php command
1. What rldowling03 says is correct. Your record of user IPs is pretty worthless since they can be trivially faked the way you have it. Just get the IP and user agent at mailing time. Referer won't work that way, so you'll have to pass it through, but that means people can fake it. You can guard against that with a checksum but explaining that is beyond the scope of this topic. 2. Your script is open to abuse by spammers, who can use it to send any message they want to anyone on the internet. This is because you pass $_POST['visitormail'] in an email header without first making sure that it contains only acceptable characters. 3. Why don't you start with a super-simple script to send a message and see if that works first: <?php mail('sales@2theletter.net', 'test', 'This is a test'); ?> Code (markup): 4. If it doesn't work, try sending to a different address (yahoo or whatever). Maybe your web server is blacklisted as a spam source and so your @2theletter.net server is dropping the message. Maybe that's because you or someone else on your web server failed to observe (2) above.