How to send mail? [SOLVED]

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
zenon
Forum Commoner
Posts: 42
Joined: Fri Jan 23, 2009 1:41 pm

How to send mail? [SOLVED]

Post 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!!
Last edited by zenon on Mon May 11, 2009 7:39 pm, edited 1 time in total.
User avatar
codex-m
Forum Newbie
Posts: 15
Joined: Sun May 10, 2009 8:08 am

Re: How to send mail?

Post 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.
zenon
Forum Commoner
Posts: 42
Joined: Fri Jan 23, 2009 1:41 pm

Re: How to send mail?

Post 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?
User avatar
codex-m
Forum Newbie
Posts: 15
Joined: Sun May 10, 2009 8:08 am

Re: How to send mail?

Post 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.
zenon
Forum Commoner
Posts: 42
Joined: Fri Jan 23, 2009 1:41 pm

Re: How to send mail?

Post 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!
zenon
Forum Commoner
Posts: 42
Joined: Fri Jan 23, 2009 1:41 pm

Re: How to send mail?

Post by zenon »

Hello.

I found the solution here.

I had to use SMTP Authentication!

Thank you all for your help!!


Best regards,
Zinon
Post Reply