使用swift邮件发送电子邮件

时间:2014-01-18 15:17:19

标签: php email swiftmailer

我尝试使用swift邮件程序发送邮件但是在提交邮件后它会显示空白页面而不发送邮件。这是我的代码。

    <?php
session_start();
include "config.php";

$query  = mysql_query("SELECT email FROM user WHERE id = '" . $_SESSION['id'] . "'");
$emailres = mysql_result($query, 0);

$user = $_SESSION['username'];


if ($_POST['submit'] != "") {
    $username = $user;
    $predmet    = $_POST["predmet"];
    $poruka    = $_POST["poruka"];
    $email = $emailres;

    if (strlen($predmet) < 3 OR strlen($predmet) > 20) {
        header("Location: error.php?error=23");
        break;
    }
    if (strlen($poruka) < 0 OR strlen($predmet) > 5000) {
        header("Location: error.php?error=24");
        break;
    }

include_once "other/swift_required.php";

$subject = $predmet;
$from = array($email => $user);
$to = array(
 'xxx@gmail.com'  => 'xxx'
);

$text = "Mandrill speaks plaintext";
$html = "<em>Mandrill speaks <strong>HTML</strong></em>";

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl');
$transport->setUsername('xxxxx@gmail.com');
$transport->setPassword('xxxxx');
$swift = Swift_Mailer::newInstance($transport);

$message = new Swift_Message($predmet);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');

if ($recipients = $swift->send($message, $failures))
{
 echo 'Message successfully sent!';
} else {
 echo "There was an error:\n";
 print_r($failures);
}

 }
?>

我尝试使用在网络上找到的引用,但没有帮助。另外,如果你知道在gmail上发送消息的任何其他方式,你可以与我分享:)

编辑:更改了代码但没有任何反应:/

0 个答案:

没有答案