Skip to main content

trying to send mail using swift mailer, gmail smtp, php



Here is my code:







<?php

require_once 'Swift/lib/swift_required.php';



$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465)

->setUsername('me@ff.com')

->setPassword('pass');



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

$message = Swift_Message::newInstance('Wonderful Subject')

->setFrom(array('me@ff.com' => 'MY NAME'))

->setTo(array('you@ss.com' => 'YOU'))

->setBody('This is the text of the mail send by Swift using SMTP transport.');

//$attachment = Swift_Attachment::newInstance(file_get_contents('path/logo.png'), 'logo.png');

//$message->attach($attachment);

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

printf("Sent %d messages\n", $numSent);

?>







AFter RUNNING GOT THIS ERROR...







Fatal error: Uncaught exception 'Swift_TransportException' with message 'Expected response code 220 but got code "", with message ""' in /home/sitenyou/public_html/Swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php:406









Stack trace:

#0 /home/sitenyou/public_html/Swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(299): Swift_Transport_AbstractSmtpTransport->_assertResponseCode('', Array)

#1 /home/sitenyou/public_html/Swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(107): Swift_Transport_AbstractSmtpTransport->_readGreeting()

#2 /home/sitenyou/public_html/Swift/lib/classes/Swift/Mailer.php(74): Swift_Transport_AbstractSmtpTransport->start()

#3 /home/sitenyou/public_html/sgmail.php(16): Swift_Mailer->send(Object(Swift_Message))

#4 {main} thrown in /home/sitenyou/public_html/Swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php on line 406





Source: Tips4all

Comments

  1. GMail's SMTP requires encryption. Use Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl").

    ReplyDelete
  2. I cannot be sure, but I think that Gmail's port is 587 using TLS, which is not SSL, but a newer version of it. You should check into that, because I think you are placing the wrong construction code.

    Best of luck!

    ReplyDelete
  3. there is missing the ssl parameter, it should be something like that

    Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")


    Tested and work fine

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 1 Final Exam 2011 latest (hot hot hot)

  Hi! I have been posted content of ccna1 final exam (latest and only question.) I will post the answer and insert image on sunday. If you care, please subscribe your email an become a first person have full test content. Subcribe now  Some question  have not content because this question have images content. So that can you wait for me? SUNDAY 1. A user sees the command prompt: Router(config-if)# . What task can be performed at this mode? Reload the device. Perform basic tests. Configure individual interfaces. Configure individual terminal lines. 2. Refer to the exhibit. Host A attempts to establish a TCP/IP session with host C. During this attempt, a frame was captured with the source MAC address 0050.7320.D632 and the destination MAC address 0030.8517.44C4. The packet inside the captured frame has an IP source address 192.168.7.5, and the destination IP address is 192.168.219.24. At which point in the network was this packet captured? leaving host A leaving ATL leaving...