priyankabhar Posted December 7, 2009 Share Posted December 7, 2009 Hi All, I am facing a problem which I am not able to solve even after googling for quite some time. So if you could help me, I would be very grateful. I am trying to email using mail() function. I installed "Free SMTP Server" and it is up running. I have following code:- $message = 'Hi There'; $header = 'From: myemail@gmail.com'; //From header is must $subject = "Feedback Form Results"; $send=mail("myemail@gmail.com", $subject, $message, $header) or die("failure"); However, I get following error:- Warning: mail() [function.mail]: SMTP server response: 550 Invalid recipient: myemail@gmail.com My php.ini has following:- [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = you@yourdomain I am using WAMP server to test the website locally. I am lost here and not sure what is going wrong. It is very important for me to code this email function correctly, but I am not able to. I am looking for your ideas and help. Thanks a lot! Priya Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/ Share on other sites More sharing options...
Deoctor Posted December 7, 2009 Share Posted December 7, 2009 hai priya dont u need to change your local domain sendmail_from = you@yourdomain to send a mail.and also can u check whether u have the port 21 opened in ur machine...one more thing as per ur error wht u are having might be it cannot able to connect to ur domain server which u have given. check whether u have mail server configured properly Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/#findComment-972646 Share on other sites More sharing options...
oni-kun Posted December 7, 2009 Share Posted December 7, 2009 $message = 'Hi There'; $header = 'From: myemail@gmail.com'; //From header is must $subject = "Feedback Form Results"; $send=mail("myemail@gmail.com", $subject, $message, $header) or die("failure"); Try adding the -f parameter to your mail() function like so: $message = 'Hi There'; $header = 'From: myemail@gmail.com'; //From header is must $subject = "Feedback Form Results"; $send=mail("myemail@gmail.com", $subject, $message, $header, '-fmyemail@gmail.com'); No space between the -f and 'from' e-mail address forced. Also note that port 21 HAS to be opened, it's an invalid recipient if it's not reachable! EDIT: You cannot use or Die on a variable. Write: if (!$send) { die('Mail error'); } Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/#findComment-972649 Share on other sites More sharing options...
priyankabhar Posted December 7, 2009 Author Share Posted December 7, 2009 Thank you all for your suggestions. But I still get the same error. My php_ini has 25 as SMTP port. I checked using helo in telnet to localhost at 25, and it replied back with "Hello localhost". So I think port 25 is open. I also changed sendmail_from = me@localhost, but it is still not working. Please tell me if my syntax is wrong. Thanks again a lot in advance. Priya Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/#findComment-972953 Share on other sites More sharing options...
Deoctor Posted December 8, 2009 Share Posted December 8, 2009 can u paste ur code here so that we can check it out.. i mean is that the entire code which u are using or something else.. Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/#findComment-973250 Share on other sites More sharing options...
priyankabhar Posted December 9, 2009 Author Share Posted December 9, 2009 Hi ym_chaitu, Here is my code:- ini_set("SMTP","smtp.utah.edu"); ini_set("sendmail_from","u0123456@utah.edu"); $message = 'Hi There'; $header = 'From: u0123456@utah.edu'; $subject = "Feedback Form Results"; $send=mail("u0123456@utah.edu", $subject, $message, $header); Thanks for taking the time to help me out here. smtp.utah.edu is the mail server. The error I am getting is:- Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.utah.edu" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() Priya Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/#findComment-974270 Share on other sites More sharing options...
premiso Posted December 9, 2009 Share Posted December 9, 2009 If on localhost it could be that your ISP blocks port 25 (which is common among most cable providers). Verify that your ISP does or does not block Port 25. If they do, there really is not away around that other than find a smtp host that does not use Port 25. Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/#findComment-974277 Share on other sites More sharing options...
FaT3oYCG Posted December 9, 2009 Share Posted December 9, 2009 you can use sendmail, or fake sendmail if you are on windows, then your problems should be resolved with propper configuration. Quote Link to comment https://forums.phpfreaks.com/topic/184229-please-help-in-mail-function-to-send-email-from-localhost/#findComment-974310 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.