Mail Sending Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Mail Sending Error

Post by my_raj_raj2 »

Hi,

I have Problem in sending mail from localhost.

The code is:

Code: Select all

$mailfrom="admin@admin.com";
  $email="my_raj_raj@yahoo.com";
  $subject='hi';

  $data="This is mail part";

  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
  $headers .= "From: ". $mailfrom."\r\n";
  mail($email,$subject,$data,$headers);
When I excute the program I got the error
Warning: 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 d:\appserv\www\mail.php on line 28
Anybody know what is the solution for it?

Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hmm, change the SMTP server configuration in php.ini? Or start an SMTP server running on localhost?
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Mail Sending Error

Post by my_raj_raj2 »

Hi ,

Thanks for ur reply.

Already I set the smtp settings in php ini.

Code: Select all

SMTP = mail.domain.com
     sendmail_from = me@localhost.com
Can u tell me any smtp running in apache?(where i download it?)

I configure php in 81 port.But smtp in 25 port is make any problem?

Thanks
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

change mail.domain.com to localhost. leave the port as 25.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Apache isn't an SMTP server, it's HTTP.

Either use a remote server or install an SMTP service. Windows servers have one you can enable in the control panel. Linux servers can use a number of things like sendmail, qmail, exim...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Alternatively, you can often use your ISP's SMTP server to send mail from PHP. Try using the same SMTP server name as you have for sending mail from your e-mail client.

Mac
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Mail Sending Error

Post by my_raj_raj2 »

Hi all,

Thanks for ur Replies.

I try several times but I got same error.

I change the settings in php.ini
; For Win32 only.
SMTP = mail.aj16.kserver.aj.com (Domain name in smtp server)

; For Win32 only.
sendmail_from = kserver@aj.com



I configure the smtp in localhost is make any problem?

Anybody tell me is that any possibilities for mail send from localhost?

Thank u.
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Mail Sending Error

Post by my_raj_raj2 »

Hi all,

If any possibilites for mail send using third party smtp(Free smtp services).

Thanks in advance
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Mail Sending Error

Post by Chris Corbyn »

my_raj_raj2 wrote:Hi all,

If any possibilites for mail send using third party smtp(Free smtp services).

Thanks in advance
http://www.swiftmailer.org/ will work with something like a Gmail account or any other SMTP server you can get access to.
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Mail Sending Error

Post by my_raj_raj2 »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

   Thanks  for ur reply.


I download the Swift-1.2.1 and run this in my localhost.

Run this coding

Code: Select all

<?php
 
//Specify secure TLS when we make the connection
$swift = new Swift(new Swift_SMTP_Connection('smtp.gmail.com', SWIFT_SECURE_PORT, SWIFT_TLS));
 
//Log in to the server
$swift->authenticate('myaccount@gmail.com', 'myaccountpassword');
 
if (!$swift->hasFailed())
{
    $swift->send(
        '"To User" <shiri@gmail.com>',
        '"Your name" <shiri@aj.com>',
        'The subject',
        'Your message'
    );
    $swift->close();
}
 
?>
But I got this error.
Parse error: syntax error, unexpected T_STRING in d:\appserv\www\Swift.php on line 65
I don't know Why it is appear?

Bye.


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Are you using the correct version of Swift Mailer

There are two versions...one for PHP5 and one for PHP4
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Mail Sending Error

Post by my_raj_raj2 »

Hi,

I am using PHP 4.4.1.

And I download the Swift-1.2.1-php4.zip.

But Now I got the error below
Fatal error: Cannot instantiate non-existent class: swift_smtp_connection in d:\appserv\www\swift_mail.php on line 4

Php code is below

Code: Select all

<?php
     require 'Swift.php';
    //Specify secure TLS when we make the connection
    $swift = new Swift(new Swift_SMTP_Connection('smtp.gmail.com', SWIFT_SECURE_PORT, SWIFT_TLS));
 
   //Log in to the server
   $swift->authenticate('myaccount@gmail.com', 'myaccountpassword'); 
  
   if (!$swift->hasFailed()) 
  { 
    $swift->send( 
        '"To User" <shiri@gmail.com>', 
        '"Your name" <shiri@aj.com>', 
        'The subject', 
        'Your message' 
    ); 
    $swift->close(); 
   } 
   ?>
Help Me. what is the wrong in this coding?

Thank u.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You haven't included the Swift_SMTP_Connection.php file ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Hmm... I'm not sure TLS will work with a windows installation of PHP. It requires OpenSSH to be compiled with PHP.... does windows PHP support ssl:// and tls:// protocols?
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Mail Sending Error

Post by my_raj_raj2 »

I include the Swift_SMTP_Connection.php file.

But mail was not send to users.

if any possiblites for mail sending (windows php)?
Post Reply