views:

125

answers:

1

I'm writing a simple script in which a gmail account is used to send an email to itself.

I altered the script from SwiftMailer's reference, but I'm not getting any results. What's wrong?

Edit: after further debugging I've found that the statement

$result = $mailer->send($message);

causes the code to fail (the echo below it doesn't print).

Why is this? Just cause the message isn't sent the program crashes? :/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>

<?php

require_once '/var/www/swift/lib/swift_required.php';


echo 'Mail sent <br />';  



//create the transport


/*
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587);

  ->setUsername('[email protected]')
  ->setPassword('softrain1234')
  ;
*/


$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587)
  ->setUsername('[email protected]')
  ->setPassword('password')
  ;


echo 'line 40 <br />';

$mailer = Swift_Mailer::newInstance($transport);



$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('[email protected]' => 'Evaluaciones'))
  ->setTo(array('[email protected]'=> 'A name'))
  ->setBody('Test Message Body')
  ;

echo 'line 52 <br />';


$result = $mailer->send($message);

echo $result;


echo 'line 58 <br />';

?>
</body>
</html>

The test form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

<html>

 <head>

   <meta http-equiv="Content-Type"
         content="text/html; charset=ISO-8859-1" />

    <title>Test Mail Script</title>


 </head>

<body>



<form action="scriptmail.php" method="post">



        <input type="submit"/>



    </table>
  </form>



  </body>


</html>
+1  A: 

The GMail SMTP system has it's issues given the SSL and ports. I find it hard to get it to work with PHP nicely.

The best thing I have found, that does work is phpGMailer. You may be able to sift through that code to see how they got it to work, but that has always worked flawlessly for me.

I know this does not address the SwiftMail issue, just figured I would point that out :)

Brad F Jacobs
Thanks, I'll look it up. Still, I wanna fix this.
omgzor