Advertisement
Guest User

Untitled

a guest
Sep 17th, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. require_once 'swiftmailer/lib/swift_required.php';
  2.  
  3. class Email_Message {
  4.  
  5. public $transport;
  6.  
  7. public function __construct($host,$port, $useremail,$emailpassword) {
  8. $this->transport = Swift_SmtpTransport::newInstance($host,$port,'ssl') //'ssl://smtp.gmail.com', 465
  9. ->setUsername($useremail)
  10. ->setPassword($emailpassword);
  11. }
  12.  
  13. public function SendEmail($subject, $MessageBody, $from = array(), $to = array()){
  14.  
  15. $mailer = Swift_Mailer::newInstance($this->transport);
  16.  
  17. $message = Swift_Message::newInstance($subject); // subject
  18.  
  19. $message->setFrom($from); // sender
  20. $message->setTo($to); // Receiver
  21.  
  22. $message->setBody($MessageBody); // message body with either text or HTML
  23.  
  24. $send = $mailer->send($message,$failuers);
  25. return $send;
  26. }
  27.  
  28. $EmailClass = new Email_Message('smtp.gmail.com', 465, "myemail@gmail.com", "mypassword");
  29.  
  30. $subject = "TESTING";
  31. $from = array('myemail@gmail.com' => 'My Name');
  32.  
  33. $to = array('useremail@mail.com' => 'username');
  34.  
  35. $MessageBody = "testing";
  36.  
  37. $check_Mail = $EmailClass->SendEmail($subject, $MessageBody, $from, $to);
  38.  
  39. if ($check_Mail){
  40. echo "Mail Sent";
  41. }
  42. else {
  43. echo $check_Mail;
  44. }
  45.  
  46. <br />
  47. <b>Fatal error</b>: Uncaught exception 'Swift_TransportException' with message
  48. 'Connection could not be established with host smtp.gmail.com
  49. [php_network_getaddresses: getaddrinfo failed: No such host is known. #0]'
  50. in C:xampphtdocsmy project directoryswiftmailerlibclassesSwiftTransportStreamBuffer.php:269
  51. Stack trace:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement