GameYin Posted April 13, 2008 Share Posted April 13, 2008 Ok, so I'm sending an email if someone wants to advertise on my website. www.gameyin.com/index.html Go to "Put Ad here" Fill out form, and I have this for advertiseaction.php <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $subject = "Advertisement on the website"; $from = "[email protected]"; $send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]"); if ($send) { echo 'Thank you for your interest, you will get replied to asap!'; header('Location: http://www.gameyin.com/index.php'); } else { echo 'Your mail wasnt sent, please try again'; } ?> Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/ Share on other sites More sharing options...
p2grace Posted April 13, 2008 Share Posted April 13, 2008 Do you have an actual question? Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-516370 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 Yes, if you would have actually WENT to the website, and done what I asked, you would see an ERROR, OMFGGGG. It says headers already sent. Do not ask whether I have a question unless you do what I ask first. Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-516599 Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2008 Share Posted April 14, 2008 You should know that forum members are not going to click on unknown links posted in the forum. If you don't copy and paste error messages into your post and don't get a response to your suggestion to go to your site to see them, don't get upset with the forum members. Also, if you read the error message it states what the problem is. There is also a sticky post in the forum for this common noob error. Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-516628 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 Members should click the link when I'm trying to get them to experience the problem. And the headers shouldn't have sent. Especially not twice. Any reason why this is happening? Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-516679 Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 Did you read the post? Did you read the forum guidelines? Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-516694 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 I will look at the PHP Help forum guidelines, I hope I see something.. Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-516990 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 So, reading hte post, I assume that my error is that I'm echoing something to the page before I send the mail? Revising my code to... <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $subject = "Advertisement on the website"; $from = "[email protected]"; $send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]"); if ($send) { header('Location: http://www.gameyin.com/index.php'); } else { header('Location: http://www.gameyin.com/advertise.php'); } ?> Output...WORKS. Though, using that code I gave you, It will always go to advertise.php for some reason. The mail isn't being sent. Any idea why? Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-516997 Share on other sites More sharing options...
darkfreaks Posted April 14, 2008 Share Posted April 14, 2008 cleaned up your post variables for injection and made your else an else if statement so it will know where to go <?php $name =trim(mysql_real_escape_string($_POST['name'])); $email = trim(mysql_real_escape_string($_POST['email'])); $message = trim(mysql_real_escape_string($_POST['message'])); $subject = "Advertisement on the website"; $from = "[email protected]"; $send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]"); if ($send||isset($send)||!empty($send)) { header('Location: http://www.gameyin.com/index.php'); } else if(!$send||empty($send)||!isset($send)) { header('Location: http://www.gameyin.com/advertise.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517004 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 You messed up on one thing. I had to add the config details for sql database. Also, using that code you gave me, what email address will the mail function send it to? Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517023 Share on other sites More sharing options...
darkfreaks Posted April 14, 2008 Share Posted April 14, 2008 add email function to check for validation and remove cleanup functions. <?php function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true;} $email=check_email_adress($email); ?> Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517028 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 Thanks for that, but I need to know why the mail isn't sending. Edit: You misspelled the call to function. You typed in adress when it's supposed to be address. Add another D Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517036 Share on other sites More sharing options...
darkfreaks Posted April 14, 2008 Share Posted April 14, 2008 sorry about that does it work when you spell it right Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517050 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 Yes it does. Also, using that code you gave me, what email address will the mail function send it to? Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517055 Share on other sites More sharing options...
darkfreaks Posted April 14, 2008 Share Posted April 14, 2008 whayt do you mean it is not sending i need errors if you have them if not add <?php ini_set('error_reporting',E_ALL);?> then tell me if you get errors Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517058 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 Figured it out. However, if I enter Name: Ryan Email: [email protected] Message: I wanna advertise The email I get is this.. Someone wants to advertise on your wetsite. The user who wants to is. User: Ryan Email: 1 I want to advertise Your welcome I am using this exact code. <?php include 'config.php'; $name =trim(mysql_real_escape_string($_POST['name'])); $email = trim(mysql_real_escape_string($_POST['email'])); $message = trim(mysql_real_escape_string($_POST['message'])); $subject = "Advertisement on the website"; $from = "[email protected]"; function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true;} $email=check_email_address($email); $send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]"); if ($send||isset($send)||!empty($send)) { header('Location: http://www.gameyin.com/index.php'); } else if(!$send||empty($send)||!isset($send)) { header('Location: http://www.gameyin.com/advertise.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517063 Share on other sites More sharing options...
darkfreaks Posted April 14, 2008 Share Posted April 14, 2008 google email validation, sounds like its a problem with the function Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517079 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 I figured validation problem. Return true is 1 and false is 2. How do I make it have the email address. I googled it. No help. Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517104 Share on other sites More sharing options...
darkfreaks Posted April 14, 2008 Share Posted April 14, 2008 should do something like <?php $email.= check_email_adress($email); if($email==TRUE) { // insert } else if($email==FALSE){ //die and error }?> Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517136 Share on other sites More sharing options...
GameYin Posted April 14, 2008 Author Share Posted April 14, 2008 Could you incorporate that into my code? I have it working and I don't want it screwed up by a nub Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517168 Share on other sites More sharing options...
darkfreaks Posted April 14, 2008 Share Posted April 14, 2008 <?php include 'config.php'; $name =trim(mysql_real_escape_string($_POST['name'])); $email = trim(mysql_real_escape_string($_POST['email'])); $message = trim(mysql_real_escape_string($_POST['message'])); $subject = "Advertisement on the website"; $from = "[email protected]"; function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true;} $email=check_email_address($email); if($email==TRUE){ $send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]"); } else if($email==FALSE){ echo "The email you have is not valid or is incorrect!";} if ($send||isset($send)||!empty($send)) { header('Location: http://www.gameyin.com/index.php'); } else if(!$send||empty($send)||!isset($send)) { header('Location: http://www.gameyin.com/advertise.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517200 Share on other sites More sharing options...
GameYin Posted April 15, 2008 Author Share Posted April 15, 2008 Let's see how this code works...cpanel is blocked by my school but I'm sure that this code will work. I won't mark solved just in case lol. Thanks Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517593 Share on other sites More sharing options...
GameYin Posted April 15, 2008 Author Share Posted April 15, 2008 Hmm, didn't work. Still has.. Someone wants to advertise on your wetsite. The user who wants to is. User: Ryan Email: 1 I love cheese Your welcome Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517864 Share on other sites More sharing options...
darkfreaks Posted April 15, 2008 Share Posted April 15, 2008 remove the function then then use post email Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-517892 Share on other sites More sharing options...
GameYin Posted April 16, 2008 Author Share Posted April 16, 2008 I originally thought of that, because someone wouldn't be using a fake email address when trying to contact me to advertise on my website. Well, I'm in school, when I get home I'll try it. PS: Can someone post on here just once more so I can just click on 'Show new replies to your posts'. Last time I had to look through all of PHP Help. lol Link to comment https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/#findComment-518389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.