473,382 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

php mail() not working

3
Hi i am writing a php code to send email from my exchange server to user. however, keep receiving the the Warning message below:
Warning: Unknown error in c:\phpdev5\www\mailtest2.php on line 5

my php code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $to = "test1@example.com";
  3. $subject = "Hi!";
  4. $body = "Hi,\n\nHow are you?";
  5. if (mail($to, $subject, $body)) {
  6.   echo("<p>Message successfully sent!</p>");
  7.  } else {
  8.   echo("<p>Message delivery failed...</p>");
  9.  }
  10. ?>
php.ini setting:
Expand|Select|Wrap|Line Numbers
  1. [mail function]
  2. ; For Win32 only.
  3.  
  4. SMTP = gss-exchange1.example.com
  5. SMTP_Port = 25
  6.  
  7. ; For Win32 only.
  8.  
  9. sendmail_from = test2@example.com
Can anyone pls tel me what's wrong with my code or php setting?

Thanks.
Feb 5 '10 #1
5 2293
wasco, you need to set up a real mailing server in order to send a real mail,
read more about mail() function on php.net ,
if you are on windows, try to use free smtp server http://www.softstack.com/freesmtp.html

if you are lucky mail will be sent !!!

also read abt setting up Gmail as SMTP server
Feb 5 '10 #2
wasco
3
@hitendrap
Hi Hitendrap,

Thanks for your reply.

I have downloaded and installed the free smtp server; no luck for me, keeping getting "Waiting for connections on Port#25; using DNS Server: 170.133.125.2 (my company dns)
Feb 8 '10 #3
Remember that DNS server is not a mailing server (you need to get the IP of mail server from ur network admin, the DNS server contains the MX record for the mail server)

Make sure you also ask for the port number once you get thr mail serevr IP and set the configuration in PHP.INI

while your mailing program is being executed, just watch the freesmtpserver window, it shows the recipients e-mail address with hourglass icon before that !
Feb 8 '10 #4
wasco
3
Hi Hitendrap,

I have added SMTP address(Given by Network admin) to the php.ini and received the following message when i execute my php program:

Warning: Unknown error in c:\phpdev5\www\mailtest3.php on line 7

my php code:

Expand|Select|Wrap|Line Numbers
  1. $to = "test1@gss.com";
  2. $subject = "Test mail";
  3. $message = "Hello! This is a simple email message.";
  4. $from = "test2@gss.com";
  5. $headers = "From: $from";
  6. mail($to,$subject,$message,$headers);
  7. echo "Mail Sent.";
  8. ?> 
Do i need to include the test2 (sender) user id and password in my php code in order to connect to my smtp mail server (exchange mail server)?

Thanks in advance!
Feb 9 '10 #5
Not necessary as far as the SMTP server allows without authentication.

and headers are optional in mail() function.

avoid writing words like test, example in mails even the addresses,
coz' some popular Mailing servers like Gmail, Yahoo may put your test mail in Spam OR even block the mail.
Feb 9 '10 #6

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

Similar topics

5
by: Bruce W...1 | last post by:
In my effort to learn PHP I'm playing with some simple email scripts. They worked a few days ago but they stopped working. The only thing I've done to this Windows 2000 PC in this time was a...
4
by: Data Goob | last post by:
This one has me stumped. How did SuSE disable the mail() function in their RPM'd version of PHP? ( This is their install-version of PHP with RPMs not what you download from PHP.net ) I have...
4
by: Tom Petersen | last post by:
Ok, I'm 99.9999999999999999999% sure there haven't been any code changes, since the date stamps of the code are older than any email 'failures' The email piece quit working using the mail.send. ...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
6
by: Dushyant | last post by:
Hi everyone, I am working on an application, where I need to mail some xml files as attachments. I tried to use System.Diagnostic.Process class but it does not provide any help for attaching a...
9
by: shror | last post by:
hi every body, i have a problem which is when i was checking my mail() form it work fine but the problem is that the form configuration is not set correctly, in details: the from var is not...
10
by: Frank | last post by:
Hi, I am hoping to find out the differences between the System.Net.Mail and System.Web.Mail. Can some nice folks post the differences; or some urls which show the differences? Great Thanks...
6
by: nextpulse | last post by:
On Fedora, using php5. The mail() function returns a success - but the mail itself is not actually sent. How do I go about debugging this? Do I need to do this at the linux command level to ensure...
7
by: undbund | last post by:
Hi I am creating a newsletter system. The software should run from desktop computer (localhost) but be able to send email to anyone on the internet. Can you guys give me some ideas on how to...
5
by: sui | last post by:
this is my code import sys, os, glob, datetime, time import smtplib ## Parameters for SMTP session port=587 SMTPserver= 'smtp.gmail.com' SMTPuser= '...@gmail.com' pw= 'fill in here'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.