Page 1 of 1

How to send mail? [SOLVED]

Posted: Sun May 10, 2009 5:26 am
by zenon
Hello.

How do i send mail from localhost (ubuntu) to all recipients?

I use postfix but it sends email only to gmail :(

Code: Select all

include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "new <new@mail.com>";
$recipient = "George <geop@mail.com>";
$subject = "Test Email";
$text = 'This is a text message.';
$html = '<html><body><p>This is a html message!</p></body></html>';
$crlf = "\n";
$headers = array(
'From'          => $sender,
'To'            => $recipient,
'Return-Path'   => $sender,
'Subject'       => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
 // Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);
// SMTP params
$smtp_params["host"] = "localhost"; // SMTP host
$smtp_params["port"] = "25";               // SMTP Port (usually 25)
// Sending the email using smtp
$mail =& Mail::factory("smtp", $smtp_params);
$result = $mail->send($recipient, $headers, $body);
if($result == 1)
{
echo("Your message has been sent!");
}
else
{
echo("Your message was not sent: " . $result);
}
 
Is there any idea?

Help!!

Re: How to send mail?

Posted: Sun May 10, 2009 9:23 am
by codex-m
zenon wrote:Hello.

How do i send mail from localhost (ubuntu) to all recipients?

I use postfix but it sends email only to gmail :(

Code: Select all

include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "new <new@mail.com>";
$recipient = "George <geop@mail.com>";
$subject = "Test Email";
$text = 'This is a text message.';
$html = '<html><body><p>This is a html message!</p></body></html>';
$crlf = "\n";
$headers = array(
'From'          => $sender,
'To'            => $recipient,
'Return-Path'   => $sender,
'Subject'       => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
 // Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);
// SMTP params
$smtp_params["host"] = "localhost"; // SMTP host
$smtp_params["port"] = "25";               // SMTP Port (usually 25)
// Sending the email using smtp
$mail =& Mail::factory("smtp", $smtp_params);
$result = $mail->send($recipient, $headers, $body);
if($result == 1)
{
echo("Your message has been sent!");
}
else
{
echo("Your message was not sent: " . $result);
}
 
Is there any idea?

Help!!
Are you using XAMPP for your localhost in sending mail? Or is there any other platforms you are using.

Re: How to send mail?

Posted: Sun May 10, 2009 9:34 am
by zenon
I'm using Apache2 on ubuntu.

I think i found what's the problem. My IP is static.

This is the answer in my email :

Code: Select all

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
 
For further assistance, please send mail to postmaster.
 
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
 
                  The mail system
 
<xxxxxxxx@hotmail.com>: host mx3.hotmail.com[65.54.244.72] said: 550
   DY-001 Mail rejected by Windows Live Hotmail for policy reasons. We
   generally do not accept email from dynamic IP's as they are not typically
   used to deliver unauthenticated SMTP e-mail to an Internet mail server.
   http://www.spamhaus.org maintains lists of dynamic and residential IP
   addresses. If you are not an email/network admin please contact your
   E-mail/Internet Service Provider for help. Email/network admins, please
   visit http://postmaster.live.com for email delivery information and support
   (in reply to MAIL FROM command)
I tried to deliver authenticated SMTP e-mail via postfix, but i got again the same answer.

Is there any idea?

Re: How to send mail?

Posted: Mon May 11, 2009 10:15 am
by codex-m
Instead of localhost try testing it on a live site, hosted in a reputable server to see if those email can be sent. It is highly possible they block email addresses originating from localhost.

Re: How to send mail?

Posted: Mon May 11, 2009 3:17 pm
by zenon
codex-m wrote:Instead of localhost try testing it on a live site, hosted in a reputable server to see if those email can be sent. It is highly possible they block email addresses originating from localhost.
Hello codex-m!

I couldn't agree the most with you. I think this is the only to way to find out!

Thank you! I'll try it out soon!

Good night!

Re: How to send mail?

Posted: Mon May 11, 2009 7:36 pm
by zenon
Hello.

I found the solution here.

I had to use SMTP Authentication!

Thank you all for your help!!


Best regards,
Zinon