473,322 Members | 1,425 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,322 software developers and data experts.

mail() with authentication doesn't work

I do not have proper excellence at php programming. I wrote below script after reading several articles. Anyway that form-to-mail script doesn't work. form action is connected to following code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once "send1.php";
  3.  
  4. $from = "Sandra Sender <user@myweb.com.com>"; 
  5. $to = "Ramona Recipient <myemail@gmail.com>";
  6. $subject = "Hi!";
  7. $body = "Hi,\n\nHow are you?";
  8.  
  9. $host = " mail.myweb.com";
  10. $username = "user@myweb.com";
  11. $password = "mypassword";
  12.  
  13. $headers = array ('From' => $from,
  14.   'To' => $to, 
  15.   'Subject' => $subject);
  16. $smtp = Mail::factory('smtp',
  17.   array ('host' => $host,
  18.     'auth' => true,
  19.     'username' => $username,
  20.     'password' => $password)); 
  21.  
  22. $mail = $smtp->send($to, $headers, $body);
  23.  
  24. if (PEAR::isError($mail)) {
  25.   echo("<p>" . $mail->getMessage() . "</p>");
  26. } else {
  27.   echo("<p>Message successfully sent!</p>"); 
  28. }
  29. ?>
  30.  
send1.php is as follows.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $to = "myemail@gmail.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. ?>
  11.  
this gets a error massage as follows.
Expand|Select|Wrap|Line Numbers
  1. Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in ....
  2.  
  3. Message delivery failed...
  4.  
  5.  
  6. Fatal error: Class 'Mail' not found in D:\websites\fff\fff.com\wwwroot\send.php on line 16
  7.  
--------------------------------------------

I don't have a server and i'm taking server from a remote company. they says mail server authentication is the prob. anyway it doesn't work.

please help me...

thanks.
Nov 5 '07 #1
1 2224
Atli
5,058 Expert 4TB
Hi. Welcome to TSDN!

Your fist warning says it all, really:
Expand|Select|Wrap|Line Numbers
  1. Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in ....
  2.  
So, as the error mentions, try giving the "smtp_port" and "SMTP" settings proper values.
Like for example:
Expand|Select|Wrap|Line Numbers
  1. ini_set("smtp_port", 25);
  2. ini_set("SMTP", "mail.example.mysmtpserver.com");
  3.  
These values are obviously made up. You will have to replace them with real values.
Nov 10 '07 #2

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

Similar topics

0
by: Google Mike | last post by:
There seems to be a lot of white noise in trying to understand SMTP that requires authentication when searching the newsgroups via Google Groups or searching the PHP.net website. The PHP fsockopen...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: Brett Porter | last post by:
Hi, My ASP.Net applications frequently make use of the System.Web.Mail namespace to send emails. I have set SmtpMail.SmtpServer = "localhost" and the emails send out fine UNTIL an email is sent...
3
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
6
by: rekaeps | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Also, in the same scenario,...
3
by: dnuos | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Here's some details: ...
6
by: AbraAbraCadabra | last post by:
Ok I think I've almost got my problem solved. I am using this code to send mail. I am simply pasting it into an .ASP page. Why doesn't this code work? I do have ..NET 2.0 installed, but I...
11
by: ibiza | last post by:
Hi all, I am trying to use the System.Net.Mail class for the first time, with ASP.NET 2.0. I setup everything according to http://www.codeproject.com/aspnet/EasySMTP_package.asp, which gives...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.