Pacopag Posted March 17, 2011 Share Posted March 17, 2011 Hi. I had some trouble getting the mail function to work, I guess because I'm developing on LAMP (localhost), but I got it working at the office yesterday by configuring things as outlined here http://mattsk.blogspot.com/2010/09/configure-lamp-on-ubuntu-1004-to-send.html This got it working fine. But today I'm trying it from home and it's not working (mail is not getting sent). I don't know how the network is set up at work, but at home I'm on wireless lan through a d-link router. I have a feeling it has something to do with the smtp_port = 465 (see link above), and that port maybe being blocked by the firewall or something. I'm not really sure how all this stuff works though. I tried contacting d-link, but they want some money before they'll help me out. I followed some instructions I found online to forward port 465, which seemed to work (at lease the router told me so). But the mail is still not sending. A also tried the "fix-almost-any-computer-problem-ever" solution (i.e. I restarted my computer). But still nothing. I hope I've come to the right place for help. Any help would be great. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/ Share on other sites More sharing options...
gristoi Posted March 17, 2011 Share Posted March 17, 2011 try changing the outgoing port to the standard port 25 instead of 465 Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1188693 Share on other sites More sharing options...
Pacopag Posted March 17, 2011 Author Share Posted March 17, 2011 Do you mean on the router? or in the php.ini? I'm pretty sure that the port 25 already is open on the router. Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1188695 Share on other sites More sharing options...
gristoi Posted March 17, 2011 Share Posted March 17, 2011 smtp_port in your php.ini Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1188696 Share on other sites More sharing options...
Pacopag Posted March 17, 2011 Author Share Posted March 17, 2011 That didn't work. In the link I used to get mail to work at the office, it says that it's using the Gmail SMTP server to send mail from localhost. I don't know if that's why he used 465. I would think that sending mail from LAMP localhost is pretty common. Is there some standard way to set things up so that localhost can send mail? Thanks for your help. I have to step out for about 20 min, so I apologize if I don't reply to the next post promptly. Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1188697 Share on other sites More sharing options...
gristoi Posted March 17, 2011 Share Posted March 17, 2011 your going to need a mail server on your lamp stack. i use postfix for my localhost. Have a look at: http://askubuntu.com/questions/25833/is-there-a-simple-mail-server-i-can-install Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1188698 Share on other sites More sharing options...
Pacopag Posted March 17, 2011 Author Share Posted March 17, 2011 Sounds good. Should I install just postfix? or dovecot-postfix? I just need something simple for testing purposes. Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1188710 Share on other sites More sharing options...
Pacopag Posted March 17, 2011 Author Share Posted March 17, 2011 So I installed dovecot-postfix, but mail() is still not working. I tried changing smtp_port = 465 to smtp_port = 25. And also tried commenting this line out completely from the php.ini file. Also, from what I read, postfix doesn't use sendmail, so maybe I need to change the line sendmail_path = /usr/sbin/sendmail -t in php.ini to something else? Can anyone tell me how to configure php to jive with postfix, or maybe a useful link? Google returns lots of stuff, but the config instructions are hundreds of lines long. I'm hoping that in reality it's just change a couple lines here or there in a few files. Also, I tried putting everything the way it was when it was working at the office. Then I bypassed the router (plugged straight into the modem), and it still didn't work. So my original theory about the port being blocked is squashed. I guess I gotta get postfix working. Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1188725 Share on other sites More sharing options...
Pacopag Posted March 18, 2011 Author Share Posted March 18, 2011 After a whole day of try..fail..try...fail...and so on, I gave up on postfix. I found a working solution that uses PEAR at http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page Installed PEAR and tried the code at the link above and it worked. Here is the working code (had to fix one small error pointed out in a later post) <?php require_once "Mail.php"; $from = "<[email protected]>"; $to = "<[email protected]>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "ssl://smtp.gmail.com"; $port = "465"; $username = "[email protected]"; $password = "password"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> <!-- end of php tag--> Quote Link to comment https://forums.phpfreaks.com/topic/230923-mail-function-works-at-the-office-but-not-at-home/#findComment-1189129 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.