Howlin1 Posted September 23, 2011 Share Posted September 23, 2011 Hello, I have a registration page and when a user registers I want to send their email an activation code. To test I have the following code. <?php //Send activation Email $to = $Email_address; $subject = "www.WEBSITE.com/"; $message = "Welcome to my website!\r\rYou, or someone using your email address, has completed registration at WEBSITE. You can complete registration by clicking the following link:\rhttp://www.WEBSITE.com/register.php?action=verify&$activationKey\r\r If this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\ "; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); if (mail($to, $subject, $message, $headers)) { echo 'Success'; } else { echo 'Error'; } ?> I have the last if else to see if it is sent to not. I do get a Success message, but I don't get an email at the address (I have checked the spam folder). I have checked the email address and it is correct. I have even waited a few hours and nothing. Why is the email not getting to my account? Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/ Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 Well, acording to this script, $to isn't actually set to anything because either is $Email_address. Also, your check is almost right. The way you have it would send two emails if it was working. It can be one of two ways: if (mail($to, $subject, $message, $headers)) { //error } else { //success } in which case you don't need the first mail() call. Otherwise you can do it like this: $check = mail($to, $subject, $message, $headers) if (!$check) { //error } else { //success } Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1272115 Share on other sites More sharing options...
Howlin1 Posted September 23, 2011 Author Share Posted September 23, 2011 Well, acording to this script, $to isn't actually set to anything because either is $Email_address. I didn't put the full script because it wasn't really needed, but there is a value for $Email_address. Well, acording to this script, $to isn't actually set to anything because either is $Email_address. I didn't put the full script because it wasn't really needed, but there is a value for $Email_address (but it's an attachment now). if (mail($to, $subject, $message, $headers)) { //error } else { //success } in which case you don't need the first mail() call. Otherwise you can do it like this: $check = mail($to, $subject, $message, $headers) if (!$check) { //error } else { //success } I only put that in to see if it was saying it was sent. It will be taken out as soon as it does actually work. if (mail($to, $subject, $message, $headers)) { //error } else { //success } in which case you don't need the first mail() call. Otherwise you can do it like this: $check = mail($to, $subject, $message, $headers) if (!$check) { //error } else { //success } I only put that in to see if it was saying it was sent. It will be taken out as soon as it does actually work. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1272120 Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 Alright. Did you echo all the variables to see they hold what they should? Maybe you should post more code; there's no reason it shouldn't work that I can see if what you say is true. Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1272121 Share on other sites More sharing options...
voip03 Posted September 23, 2011 Share Posted September 23, 2011 your code $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); Replace this code $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: $from\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1272124 Share on other sites More sharing options...
Howlin1 Posted September 23, 2011 Author Share Posted September 23, 2011 @ DevilsAdvocate I did echo out the variables and they contain what they are meant to contain. I even removed everything in the script and put in information myself, and still nothing. I have added the full script as an attachment. @voip03 I did that and still nothing. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1272128 Share on other sites More sharing options...
Pikachu2000 Posted September 23, 2011 Share Posted September 23, 2011 Have you checked with your host to make sure there are no special requirements such as adding an optional fifth parameter to the mail() function? Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1272129 Share on other sites More sharing options...
Howlin1 Posted September 23, 2011 Author Share Posted September 23, 2011 No, I didn't know it might depend on my host. I'll drop them an email and ask. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1272132 Share on other sites More sharing options...
Howlin1 Posted September 29, 2011 Author Share Posted September 29, 2011 I got a reply back. I can send an email to a hotmail account but not a gmail account. Me: What would the reason behind the email not being sent to the gmail account? Host: That's generally a mystery deep in the mind of Google I'm afraid. Getting any sort of visibility out of them on that is an eternal struggle. To me that sounds like they don't know. It looks like I'll have to (try) email google and ask them :/ Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274130 Share on other sites More sharing options...
Jacbey Posted September 29, 2011 Share Posted September 29, 2011 Ok, that's complete twaddle. I can send to a gmail address using my php form. Here, this is a form I quickly put together for you. Change the email address that it's sending to and see if it'll work. klueless.net/basic%20email%20form%20php.zip Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274141 Share on other sites More sharing options...
Pikachu2000 Posted September 29, 2011 Share Posted September 29, 2011 Is the From: header set to a valid email address on your server? Many times emails are dropped when the From: address doesn't resolve back to the sending server. In other words, the From: header should not be set to the address the user entered in the form. Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274150 Share on other sites More sharing options...
Howlin1 Posted September 29, 2011 Author Share Posted September 29, 2011 Is the From: header set to a valid email address on your server? Many times emails are dropped when the From: address doesn't resolve back to the sending server. In other words, the From: header should not be set to the address the user entered in the form. Yes. The emails will deliver to a hotmail email (granted they get sent to the junk mail) but not a gmail one. @Jacbey I tried that form and it wouldn't send it to my email address. Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274152 Share on other sites More sharing options...
Jacbey Posted September 29, 2011 Share Posted September 29, 2011 Quite possibly because you didn't change the email in the send.php file.. Try it here, i've modified it so it sends the email to the address you put in the email box. http://klueless.net/basic%20email%20form%20php/index.html Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274155 Share on other sites More sharing options...
Howlin1 Posted September 29, 2011 Author Share Posted September 29, 2011 Your form does work when I put my gmail or hotmail email address into it, but when I try and send one to my gmail (via the form you linked to in the zip) it won't send, but it will send an email to my hotmail address. Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274164 Share on other sites More sharing options...
Jacbey Posted September 29, 2011 Share Posted September 29, 2011 go into send.php and change the $to to your own email address. =] Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274171 Share on other sites More sharing options...
Howlin1 Posted September 29, 2011 Author Share Posted September 29, 2011 I have tried that. I have also tried putting $to = $email and $to = $from and nothing will send to my gmail account but it will send to my hotmail. (I am sure the file is up to date and I use correct email addressed.) Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274174 Share on other sites More sharing options...
Howlin1 Posted September 29, 2011 Author Share Posted September 29, 2011 Anyone able to help? Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274212 Share on other sites More sharing options...
Howlin1 Posted September 30, 2011 Author Share Posted September 30, 2011 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274541 Share on other sites More sharing options...
Pikachu2000 Posted September 30, 2011 Share Posted September 30, 2011 The fact that it successfully sends to one account indicates it is not a PHP problem. Quote Link to comment https://forums.phpfreaks.com/topic/247722-email-wont-send-with-php/#findComment-1274547 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.