ROCKSTAR Posted February 27, 2008 Share Posted February 27, 2008 Hey guys, I'm trying to send mail through a form, I've followed a number of tutorials and it seems as if the code is correct, it doesnt error but I don't get any mail through.. the code for my sendmail.php is below - any pointers would be great. <? $name=$_POST['name']; $email=$_POST['email']; $comment=$_POST['comments']; $to="[email protected]"; mail($to, "Message from my PHP page", $comment, $email); ?> Link to comment https://forums.phpfreaks.com/topic/93357-send-mail-mail-function/ Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 The 4th argument needs to be a header. Something like this should work: <?php $name=$_POST['name']; $email=$_POST['email']; $comment=$_POST['comments']; $to="[email protected]"; $subject = "Message from my PHP page"; $headers = "From: $email\r\n"; mail($to, $subject, $comment, $headers) or die("Couldn't send mail"); ?> Link to comment https://forums.phpfreaks.com/topic/93357-send-mail-mail-function/#findComment-478228 Share on other sites More sharing options...
freenity Posted February 27, 2008 Share Posted February 27, 2008 if you are sending the email to a hotmail box, the problem might be in headers. Check this: http://gwphp.feudal-times.net/?p=4 it's a function that sends email fine... and tested. Link to comment https://forums.phpfreaks.com/topic/93357-send-mail-mail-function/#findComment-478242 Share on other sites More sharing options...
ROCKSTAR Posted February 27, 2008 Author Share Posted February 27, 2008 Thanks to the quick replies guys... I'm still getting 100% performance and 0% results though - think perhaps its something on the server causing a problem. Thanks again for the help - if the solution turns out to be freakish I'll post my findings. Link to comment https://forums.phpfreaks.com/topic/93357-send-mail-mail-function/#findComment-478245 Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 Another problem that is becoming more common is a hosting service blocking mail with a FROM header that is outside the domain. Trying using a FROM header with an email address from your domain. So, let's forget out the POST for now, and just get email working. Assuming your domain is 'mydomain.co.uk', try this: <?php $to="[email protected]"; $from="[email protected]"; $subject = "Message from my PHP page"; $comment = "My message goes here"; mail($to, $subject, $comment, "From: $email") or die("Couldn't send mail"); print "Email Sent"; ?> Also, if you have a spam filter make sure you check that. Link to comment https://forums.phpfreaks.com/topic/93357-send-mail-mail-function/#findComment-478281 Share on other sites More sharing options...
ROCKSTAR Posted February 28, 2008 Author Share Posted February 28, 2008 Thanks rhodesa, I'll give it a try and let you know the results... Link to comment https://forums.phpfreaks.com/topic/93357-send-mail-mail-function/#findComment-478943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.