cocpg Posted March 4, 2010 Share Posted March 4, 2010 Hi guys, Help with my email function would be greatly appreciated. I have an object orientated system. One class is called 'mailer'. A function within this class is called 'sendWelcome': class mailer { function sendWelcome($user, $email, $pass){ $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; $subject = "Welcome to Tenancy Tools"; $body = $user.",\n\n" ."Welcome! You've just registered at Tenancy Tools " ."with the following information:\n\n" ."Username: ".$user."\n" ."Password: ".$pass."\n\n" ."If you ever lose or forget your password, a new " ."password can be generated for you and sent to this " ."email address. If you would like to change your " ."email address you can do so by going to the " ."My Account page after signing in.\n\n" ."- Admin"; return mail($email,$subject,$body,$from); } }; /* Initialize email object */ $mailer = new mailer; This line: $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">"; uses 'library.php', where the following is declared: define("EMAIL_FROM_NAME", "Admin"); define("EMAIL_FROM_ADDR", ""); define("EMAIL_WELCOME", true); (note that I have removed the email address for this thread, but it is correctly declared in the script). The sendWelcome function is called within the 'registration' function within the 'user' script: if(EMAIL_WELCOME){ $mailer->sendWelcome($remail,$rpass); } My issue is that nothing happens when the sendWelcome function is called (email is not sent to my email address when i test the registration process). The user is correctly registered (i.e. the data class behaves as it should, and the user gets a row in the user table). It is only the email that does not send. Could anyone explain why it is not working? Many thanks for any help that can be provided! (note: i have provided as much information as I can think of - if anyone requires more info, I will happily oblige) Regards Chris (On a related note, does anyone know whether 'email' is a protected function/name? I wasn't able to use it as the name of a class/object) Quote Link to comment Share on other sites More sharing options...
Deoctor Posted March 4, 2010 Share Posted March 4, 2010 does it gave any error for you?? and also in the place of return mail($email,$subject,$body,$from); change it to mail($email,$subject,$body,$from); try adding this to ur script error_reporting(E_ALL); and tell me what is the error it gives.. Quote Link to comment Share on other sites More sharing options...
cocpg Posted March 4, 2010 Author Share Posted March 4, 2010 no errors i'm afraid, even with error_reporting(E_ALL); - i can't really think of a way to get any feedback from this function changing 'return mail' to just 'mail' does not seem to have any impact thank you for the suggestions - I don't suppose you have any more ideas? Regards Chris Quote Link to comment Share on other sites More sharing options...
Deoctor Posted March 4, 2010 Share Posted March 4, 2010 check this in your server <?php $to = ""; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "[email]dr.virus.india@gmail.com[/email]"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent to " .$to." <b>from Email Id</b> ".$from ; ?> and tell me weather u can send mails or not Quote Link to comment Share on other sites More sharing options...
cocpg Posted March 4, 2010 Author Share Posted March 4, 2010 check this in your server <?php $to = ""; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "[email]dr.virus.india@gmail.com[/email]"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent to " .$to." <b>from Email Id</b> ".$from ; ?> and tell me weather u can send mails or not i ran it through in a separate script, this was the output: Mail Sent to chris from Email Id [here was my correct email address] So it looks like is working server side, *but* my email account never receives the email. It isn't in inbox or spam filter so i know it hasn't arrived. I should mention that the hosting company (000webhost) supposedly supports the mail function, so it shouldn't be due to them that this doesn't work Chris Quote Link to comment Share on other sites More sharing options...
askbapi Posted March 4, 2010 Share Posted March 4, 2010 Check ur SMTP setting! And pls. tell what type of server ar u using? local or remort Quote Link to comment Share on other sites More sharing options...
Deoctor Posted March 5, 2010 Share Posted March 5, 2010 000webhost supports mail functionality but this mail u ll receive a little late as it needs to be posted through port 25 check your mail after some time u'll definitely receive the mail. one more thing at the place of too have u given the mail id or name.. Quote Link to comment Share on other sites More sharing options...
cocpg Posted March 5, 2010 Author Share Posted March 5, 2010 Issue Resolved. Thanks for everyone's input. It turned out to be the host after all. I received this message from 000webhost: there were some problems with mail() on server37 and another server also I think. Try creating a test page like this: <?php echo mail('you@you.com','test subj','test msg',"From: you@000webhost.com\r\n"); ?> (replace with your email address) Hit the page in the browser and it will output true or false (1 or 0). It should work as shown (1). If not (0), try creating a new account on a different server. You could do the one-click backup and restore. They really are quite a poor host to go with. I would recommend that no one actually pay for their services, and only use the free hosting for mucking around on. It is a completely inappropriate service for any important project. Anyway, apologies for the wasted input from everyone. Regards Chris Quote Link to comment 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.