Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP Mail Not Working?

chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#1: Feb 22 '07
hi there...

i wrote this super simple PHP script to send an email to myself... but it's not sending the email... i am using Apache on my Mac (and it's installed just fine)... when i execute the script, it displays the echo message fine, but never an email... what am i doing wrong?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Send PHP Mail</title>
  4. </head>
  5. <body>
  6. <?php
  7. $to = "blablabla@gmail.com";
  8. $subject = "PHP Is Great";
  9. $body = "PHP is one of the best scripting languages around";
  10. $headers = "From: webmaster@gowansnet.com\n";
  11. mail($to,$subject,$body,$headers);
  12. echo "Mail sent to $to";
  13. ?>
  14. </body>
  15. </html>
  16.  
"blablabla@gmail.com" isn't really my email address, but it's a gmail address... i just don't understand this...

any ideas?

thanks

Newbie
 
Join Date: Feb 2007
Posts: 1
#2: Feb 22 '07

re: PHP Mail Not Working?


Works fine for me when I upload it to a server, change the email address to me and run the script.

Sorry I can't help more, but I reckon it's your environment and NOT your coding :-)
Newbie
 
Join Date: Feb 2007
Posts: 5
#3: Feb 22 '07

re: PHP Mail Not Working?


Mostly the problem comes from your email provider you use microsoft came the the genius idea to make a senders id which cant be get if you send emails via the php mail function

this should prevent you from spaming so check your junk box ;)

it can be fixed by good headering you need to give the servers address that the dns request works and your mail wont be spam
chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#4: Feb 22 '07

re: PHP Mail Not Working?


thanks for the replies...

unfortunately nothing landed in my junk mail... :-/

how would i code a header to give the server's address that a dns requests?
cassbiz's Avatar
Familiar Sight
 
Join Date: Oct 2006
Location: Florida
Posts: 204
#5: Feb 22 '07

re: PHP Mail Not Working?


Take a look at the error logs. There is a lot of information there.

If your php is not outputting any error logs (default) you need to find this line in your php.ini and uncomment it or turn it on

Expand|Select|Wrap|Line Numbers
  1. log_errors = On
  2.  
and then tell it where to store the logs

Expand|Select|Wrap|Line Numbers
  1. error_log = /var/log/php/error_log
  2.  
to view the logs in real time the command from bash is

Expand|Select|Wrap|Line Numbers
  1. cd /var/log/php/error_log
  2. tail -f error_log
  3.  
Good luck. BTW my guess it has something to do with sendmail not getting out.
chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#6: Feb 23 '07

re: PHP Mail Not Working?


thanks for the advice cassbiz... i'll defiantly look into that...
chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#7: Feb 26 '07

re: PHP Mail Not Working?


this is what my PHP.ini file looks like concerning the mail function... shouldn't that work with the code i've first written in this discussion's first post?

any help will be greatly appreciated

Expand|Select|Wrap|Line Numbers
  1. [mail function]
  2. ; For Win32 only.
  3. SMTP = localhost
  4. smtp_port = 25
  5.  
  6. ; For Win32 only.
  7. ;sendmail_from = me@example.com
  8.  
  9. ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
  10. ;sendmail_path =
  11.  
  12. ; Force the addition of the specified parameters to be passed as extra parameters
  13. ; to the sendmail binary. These parameters will always replace the value of
  14. ; the 5th parameter to mail(), even in safe mode.
  15. ;mail.force_extra_parameters =
  16.  
  17.  
Nert's Avatar
Member
 
Join Date: Nov 2006
Location: Philippines
Posts: 64
#8: Feb 27 '07

re: PHP Mail Not Working?


Quote:

Originally Posted by chunk1978

this is what my PHP.ini file looks like concerning the mail function... shouldn't that work with the code i've first written in this discussion's first post?

any help will be greatly appreciated

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

hi chunk,

i guess you're missing something in your php.ini configuration for mail function..,
did you made any changes to this part? I think these are the default value right?

Expand|Select|Wrap|Line Numbers
  1. mail function]
  2. ; For Win32 only.
  3. SMTP = localhost
  4. smtp_port = 25
  5.  
  6. ; For Win32 only.
  7. ;sendmail_from = me@example.com
try to change the value of the following into something like these.

SMTP = (your SMTP server for example mail.smtp.com)
sendmail_from = (uncomment it first then put a value for example your email address me@smtp.com)
chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#9: Feb 27 '07

re: PHP Mail Not Working?


Quote:

Originally Posted by Nert

hi chunk,

i guess you're missing something in your php.ini configuration for mail function..,
did you made any changes to this part? I think these are the default value right?

Expand|Select|Wrap|Line Numbers
  1. mail function]
  2. ; For Win32 only.
  3. SMTP = localhost
  4. smtp_port = 25
  5.  
  6. ; For Win32 only.
  7. ;sendmail_from = me@example.com
try to change the value of the following into something like these.

SMTP = (your SMTP server for example mail.smtp.com)
sendmail_from = (uncomment it first then put a value for example your email address me@smtp.com)

hey Nert, thanks for the reply...

i've changed my PHP.ini file to this:

Expand|Select|Wrap|Line Numbers
  1. [mail function]
  2. ; For Win32 only.
  3. SMTP = smtphm.sympatico.ca
  4. smtp_port = 25
  5.  
  6. ; For Win32 only.
  7. sendmail_from = jmattie@sympatico.ca
  8.  
but still nothing... there's nothing in my junk mail either... this is totally confusing me...

i'm not sure if it matters, but i'm using Apache 1.3 and Safari 2.0, with Mac OS X 10.4.8, on an Intel Core 2 Duo iMac...
chunk1978's Avatar
Familiar Sight
 
Join Date: Jan 2007
Posts: 226
#10: Feb 27 '07

re: PHP Mail Not Working?


ok...so i've realized that i'm on a UNIX machine (i'm dumb :-p) and therefore i'm suppose to specify the sendmail_path... but it's still not working :-(

here in my PHP.ini file config for the Mail Function:
Expand|Select|Wrap|Line Numbers
  1. [mail function]
  2. ; For Win32 only.
  3. SMTP = localhost
  4. smtp_port = 25
  5.  
  6. ; For Win32 only.
  7. sendmail_from = me@example.com
  8.  
  9. ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
  10. sendmail_path = /usr/sbin/sendmail
  11.  
Reply