Code: Select all
<?php
require_once "./lib/swift_required.php";
function sendMail()
{
//Create the Transport
$transport = Swift_SmtpTransport::newInstance("localhost", 25);
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance();
$message->setFrom("yzhang03@students.poly.edu");
$message->setTo("yzhang03@students.poly.edu");
$message->setSubject("This is a subject");
$message->setBody("This is mail body");
echo $message->toString();
try
{
$result = $mailer->send($message);
echo $result;
}
catch (Swift_ConnectionException $e)
{
echo 'There was a problem communicating with SMTP: ' . $e->getMessage();
}
if ($mailer->send($message))
{
echo "Message sent!";
}
else
{
echo "Message could not be sent.";
}
}
sendMail();
?>
Message-ID: <1246992745.4a53996908c93@swift.generated>
Date: Tue, 07 Jul 2009 11:52:25 -0700
Subject: This is a subject
From: yzhang03@students.poly.edu
To: yzhang03@students.poly.edu
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
This is mail body Message sent!
But why actually I didn't get the message?
I have tried different kind of emails,like yahoo, gmail...they all doesn't work
PS: I do have try to use Linux command mail to send the email, that success.
Thanks a lot for any help!!!