By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,722 Members | 1,904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,722 IT Pros & Developers. It's quick & easy.

PHP Mail Not Working?

chunk1978
100+
P: 224
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
Feb 22 '07 #1
Share this Question
Share on Google+
9 Replies


P: 1
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 :-)
Feb 22 '07 #2

P: 5
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
Feb 22 '07 #3

chunk1978
100+
P: 224
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?
Feb 22 '07 #4

cassbiz
100+
P: 202
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.
Feb 22 '07 #5

chunk1978
100+
P: 224
thanks for the advice cassbiz... i'll defiantly look into that...
Feb 23 '07 #6

chunk1978
100+
P: 224
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.  
Feb 26 '07 #7

Nert
P: 64
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)
Feb 27 '07 #8

chunk1978
100+
P: 224
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...
Feb 27 '07 #9

chunk1978
100+
P: 224
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.  
Feb 27 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.