Fatal error: Class 'Swift_SmtpTransport' not found - php

I am trying to get this mail sent on registration using SwiftMailer, however it keeps throwing this error.
I am using this add-on for osCommerce:
http://addons.oscommerce.com/info/901
I have followed the exact instructions as per what he said. Also added permissions still the same thing.
I am posting the code below:
CODE:
if (EMAIL_TRANSPORT == 'smtp') {
include_once(DIR_FS_CATALOG.DIR_WS_CLASSES . 'SwiftEmailer/swift_required.php');
$body = $this->html;
$body = preg_replace("[]",'',$body);
$host_name = explode('://',EMAIL_SMTP_HOST_SERVER);
if(count($host_name)>1){
$transport = Swift_SmtpTransport::newInstance($host_name[1], EMAIL_SMTP_PORT_SERVER, $host_name[0])
->setUsername(EMAIL_SMTP_USERNAME)
->setPassword(EMAIL_SMTP_PASSWORD);
} else {
$transport = Swift_SmtpTransport::newInstance(EMAIL_SMTP_HOST_SERVER, EMAIL_SMTP_PORT_SERVER)
->setUsername(EMAIL_SMTP_USERNAME)
->setPassword(EMAIL_SMTP_PASSWORD);
}
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($subject)
->setFrom(array($from_addr => $from_name))
->setTo(array($to_addr => $to_name))
->setMaxLineLength(50);
if($body){
$message->setBody($body, 'text/html', CHARSET);
}
if($this->text){
$message->setBody($this->text, 'text/plain', CHARSET);
}
else{
$message->setBody($this->html_text, 'text/html', CHARSET);
}
$mailer->send($message);
}
If anyone could help me sort out this issue that would be great. Thank you

Related

Call to undefined method Google_Service_Gmail_Message::toSimpleObject()

I'm trying to develop a web application that send email throught Gmail API.
But I'm getting this error :
Call to undefined method Google_Service_Gmail_Message::toSimpleObject()
Here is my code :
// LOAD GOOGLE LIBRARY
$this->CI->load->library('master_google');
$this->CI->load->library('master_phpmailer');
$client = $this->CI->master_google->getClient($data);
$mail = $this->CI->master_phpmailer;
$mail->setFrom($data->sender_email, $data->sender_name);
$mail->addReplyTo($data->response_email, $data->response_name);
$mail->addAddress($data->email);
$mail->Subject = $data->subject;
$mail->msgHTML(htmlspecialchars_decode($data->body));
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
$encoded_message = base64url_encode($mime);
// Gmail Message Body
**$message = new Google_Service_Gmail_Message();**
$message->setRaw($encoded_message);
// Send the Email
$service = new Google_Service_Gmail($client);
$email = $service->users_messages->send('me',$message);
if($email->getId()){
return array('stat' => true, 'msg' => '');
} else {
return array('stat' => false, 'msg' => '');
}
The error is generated on this line :
$message = new Google_Service_Gmail_Message();
Any help is appreciated.
I found what was the problem lol, I had a model with the same name : Google_model, I rename that to Mygoogle_model and it works :D
I think the method toSimpleObject() does not exist in your gmail-api class.

Swiftmailer breaks down after staging

I'm bringing the (Laravel-based) website for an event that's coming up soon, up to date. Part of this was improving the mailing function, for which I decided to use Mandrill's SMTP with SwiftMailer. Everything worked perfectly while working locally. However, since we pushed everything to a live (well, testing, but on the same server as live) staging area, no mails get sent anymore.
Everything seems to break down after I make a send() command in PHP. Even a simple print command doesn't do anything. There's also no errors being reported, except if I go look in my console, where the request returns a 500 Internal Server Error, without any other errors.
At the moment, these are the function I'm using only to test, which works and sends perfectly on local and then prints, but just gives a white screen on the staging area...
Route::any('test', function()
{
testMail();
//this print works perfectly locally but shows nothing on staging
print ('boe');
});
function testMail(){
$to = array('private#email.address' => 'My Name');
$subject = 'test mail';
$text = "test mail hier";
$htmlTekst = "<b>boe</b><i>spaghetti</i>";
$view = View::make('mailTemplate',
['naam' => 'Jeroen Cuvelier',
'tekst' => $htmlTekst,
'username' => 'my email address',
'password' => 99999,
'siteUrl' => rootUrl(),
'header2' => '']);
$html = $view->render();
sendEmail($text, $html, $to, $subject, "", "");}
function sendEmail($text, $html, $to, $subject, $attachment, $attachmentName)
{
//$subject = 'Subject!';
$from = array('event#email.company' =>'Company event');
/*
SMTP-settings
*/
$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 25);
$transport->setUsername('MY_MANDRILL_USERNAME');
$transport->setPassword('MY_MANDRILL_PASSWORD');
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
if ($attachment != "")
{
$toAttach = Swift_Attachment::fromPath($attachment);
if ($attachmentName!="")
{
$toAttach->setFilename($attachmentName);
}
$message->attach($toAttach);
}
//neither of these messages print on staging
if ($recipients = $swift->send($message, $failures))
{
echo 'Message successfully sent!';
} else {
echo "There was an error:\n";
print_r($failures);
}
}
Turns out the problem was not in PHP or anything I had done. The server just didn't allow SMTP calls. A call to the company hosting that fixed my issues.

Yii Mailer doesn't work

I trying to send mail using yii simple mailer ...
I followed the step :
http://www.yiiframework.com/extension/yii-simple-mailer/
And download the extension and put in yii extension folder :
https://github.com/tlikai/YiiMailer
Then put the code to config/main.php:
'mailer' => array(
// for smtp
'class' => 'ext.mailer.SmtpMailer',
'server' => 'theserver',
'port' => '25',
'username' => 'theadmin',
'password' => 'thepassword',
// for php mail
'class' => 'ext.mailer.PhpMailer',
),
Then in my controller I wrote this code to send mail:
$to = 'wahaha#gmail.com';
$subject = 'Hello Mailer';
$content = 'Some content';
Yii::app()->mailer->send($to, $subject, $content);
Then the browser gave me the error :
Property "PhpMailer.server" is not defined.
Did I miss something in my code?
In config/main.php
'Smtpmail'=>array(
'class'=>'ext.smtpmail.PHPMailer',
'Host'=>"localhost",
'Username'=>'thesmile1019#gmail.com',
'Password'=>'wakakaka',
'Mailer'=>'smtp',
'Port'=>25,
'SMTPAuth'=>true,
),
In Component/controller.php
public function mailsend($to,$from,$from_name,$subject,$message)
{
$mail = Yii::app()->Smtpmail;
$mail->SetFrom($from,$from_name);
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->AddAddress($to, "");
// Add CC
if(!empty($cc)){
foreach($cc as $email){
$mail->AddCC($email);
}
}
// Add Attchments
if(!empty($attachment)){
foreach($attachment as $attach){
$mail->AddAttachment($attach);
}
}
if(!$mail->Send()) {
return false; // Fail echo "Mailer Error: " . $mail->ErrorInfo;
}else {
return true; // Success
}
}
In controller
public function actionSendMail(){
$token = $_POST['YII_CSRF_TOKEN'];
if ($token !== Yii::app()->getRequest()->getCsrfToken()){
Yii::app()->end();
}
$to = 'thesmile1019#gmail.com';
$from = 'localhost';
$from_name = 'mface';
$subject = 'testing';
$message = 'testing';
if($token == true){
$util = new Utility();
$util->detectMobileBrowser();
$util->checkWebSiteLanguageInCookies();
$this->layout = "masterLayout";
$this->render('mailsend');
$this->mailsend($to,$from,$from_name,$subject,$message);
}else{
print_r("Not Sent");
die();
}
}
Process not problem going correct but didn't receive the mail
Change your port in pathtowebroot/protected/config/main.php
'Smtpmail'=>array(
'class'=>'ext.smtpmail.PHPMailer',
'Host'=>"smtp.gmail.com",
'Username'=>'thesmile1019#gmail.com',
'Password'=>'wakakaka',
'Mailer'=>'smtp',
'Port'=>465,
'SMTPAuth'=>true,
'SMTPSecure' => 'ssl'
),

Trouble using PEAR's Mail_Queue

I'm trying to implement PEAR's Mail_Queue package to queue some emails for a web application. I've used the documentation at http://pear.php.net/manual/en/package.mail.mail-queue.mail-queue.tutorial.php to write a small test script.
My problem is that the database is not being updated, and it's not producing errors.
EDIT
// mail_queue db options
$db_options['type'] = 'mdb2';
$db_options['dsn'] = DSN;
$db_options['mail_table'] = 'mail_queue';
// mail_queue sending options
$mail_options['driver'] = 'smtp';
$mail_options['host'] = 'smtp.gmail.com';
$mail_options['port'] = 25;
$mail_options['localhost'] = $host;
$mail_options['auth'] = true;
$mail_options['user'] = MAILUSER;
$mail_options['pass'] = MAILPASS;
require "Queue.php";
$mail_queue =& new Mail_Queue($db_options,$mail_options);
$from = 'someone#domain.ca';
$to = 'martin#starmedia.ca';
$message = 'This is a test';
$headers = array('From' => $from,
'To' => $to,
'Subject' => 'Someone has sent you an email!');
$mime =& new Mail_mime();
$mime->setTXTBody($message);
$body = $mime->get();
$headers = $mime->headers($headers,true);
print $mail_queue->put($from,$to,$headers,$body);
This produces the error Mail Queue Error: Cannot connect to database . However I checked all of the connection information and it's correct. Also, adding if (PEAR::isError($mail)) die($mail->getMessage()); produces no errors!
OK, I finally have my mail queue file working. Here are the steps I took to get it to function:
1. Enable error messages
To enable error handling, I added this snippet:
function handle_pear_error($e) {
die($e->getMessage() . ' ' . print_r($e->getUserInfo(), true));
}
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error');
Once I added this, I reloaded the page and I was getting the following error:
Call to undefined function: MDB2_Driver_mysql::_isNewLinkSet()
2. Update MDB2's MySQL driver
I searched that error and found that it's usually a result of either not having an up-to-date MDB2 library or its MySQL driver.
So I updated both and it's working!

EWS - php sending email with attachment

I'm new to using EWS from Exchangeclient classes.
I'm looking for a simple example how to send an email with an attachment. I've found examples about how to send an email but not sending an email with an attachment.
This is my script:
$exchangeclient = new Exchangeclient();
$exchangeclient->init($username, $password, NULL, 'ews/Services.wsdl');
$exchangeclient->send_message($mail_from, $subject, $body, 'HTML', true, true);
function - PHP Classes:
function send_message($to, $subject, $content, $bodytype="Text", $saveinsent=true, $markasread=true) {
$this->setup();
if($saveinsent) {
$CreateItem->MessageDisposition = "SendOnly";
$CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = "sentitems";
}
else
$CreateItem->MessageDisposition = "SendOnly";
$CreateItem->Items->Message->ItemClass = "IPM.Note";
$CreateItem->Items->Message->Subject = $subject;
$CreateItem->Items->Message->Body->BodyType = $bodytype;
$CreateItem->Items->Message->Body->_ = $content;
$CreateItem->Items->Message->ToRecipients->Mailbox->EmailAddress = $to;
if($markasread)
$CreateItem->Items->Message->IsRead = "true";
$response = $this->client->CreateItem($CreateItem);
$this->teardown();
if($response->ResponseMessages->CreateItemResponseMessage->ResponseCode == "NoError")
return true;
else {
$this->lastError = $response->ResponseMessages->CreateItemResponseMessage->ResponseCode;
return false;
}
}
You have to first save the email as a draft (with the appropriate message disposition), then CreateAttachment() so it has an attachment, then edit it with UpdateItem() so the message disposition is SendOnly. Then it will be sent.
See David Sterling's reply on this thread: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/f7d5257e-ec98-40fd-b301-f378ba3080fd/ (It's about Meeting Requests but they work the same way.)

Categories