How to send email with phpmailer in phalcon php - email

Im new in phalcon want a working example of phpmailer that send email from my site. currently i just figure out like this. i just follow this link: github.com/asyamedya/phalcon-phpmailer.
[config.php]
$config = new Phalcon\Config(array(
"app" => array(
"controllersDir"=> "app/controllers/",
"modelsDir" => "app/models/",
"viewsDir" => "app/views/",
"pluginsDir" => "app/plugins/",
"libraryDir" => "app/library/",
"helpersDir" => "app/helpers/",
"formsDir" => "app/forms/",
"cacheDir" => "cache/volt/",
"logsDir" => "cache/logs/",
"encryptKey" => "",
"baseUri" => "/demo/",
"StaticBaseUri" => "http://localhost/demo/",
"debug" => '0',
),
"mail" => array(
"driver" => "smtp",
"host" => "smtp.gmail.co",
"username" => "2munax#gmail.com",
"password" => "*****",
"security" => "tls", //ssl:465, tls:587
"port" => 587,
"charset" => "UTF-8",
"email" => "2munax#gmail.com",
"name" => "webmaster",
),
));
[loader.php]
use Phalcon\Loader;
$loader = new Loader();
$loader->registerDirs(
array(
APP_PATH . $config->app->controllersDir,
APP_PATH . $config->app->modelsDir,
APP_PATH . $config->app->pluginsDir,
APP_PATH . $config->app->libraryDir,
APP_PATH . $config->app->helpersDir,
APP_PATH . $config->app->formsDir,
APP_PATH . $config->app->cacheDir,
)
)->register();
[service.php]
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\Router;
use Phalcon\Security;
use \PHPMailer as PHPMailer;
use Phalcon\Mvc\View\Engine\Volt;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Flash\Session as FlashSession;
use Phalcon\Logger\Adapter\File as Logger;
use Phalcon\Mvc\Model\Metadata\Apc as ApcMetaData;
use Phalcon\Session\Adapter\Files as SessionAdapter;
require(APP_PATH . $config->app->libraryDir . 'PHPMailer/PHPMailerAutoload.php');
$di->set('pmailer', function() use ($config){
$pmailer = new PHPMailer();
//$mail->setLanguage('fr', '/optional/path/to/language/directory/');
$pmailer->isSMTP(true);
$pmailer->SMTPDebug = 2; // Enable verbose debug output
$pmailer->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$pmailer->Charset = $config->mail->charset;
$pmailer->Host = $config->mail->host;
$pmailer->SMTPAuth = true;
$pmailer->Username = $config->mail->username;
$pmailer->Password = $config->mail->password;
$pmailer->SMTPSecure = $config->mail->security;
$pmailer->Port = $config->mail->port;
$pmailer->addAddress($config->mail->email,$config->mail->name);
$pmailer->isHTML(true);
return $pmailer;
});
[controller index]
public function SendmailAction()
{
$this->pmailer->From = "2munax#gmail.com";
$this->pmailer->FromName = "user";
$this->pmailer->addReplyTo("2munax#gmail.com", "user");
$this->pmailer->addAddress('babymachinery83#gmail.com');
$this->pmailer->Subject = "email test !";
$this->pmailer->Body = "success!";
$this->pmailer->WordWrap = 70;
if(!$this->pmailer->send()){echo 'Message could not be sent.';
echo 'Mailer Error: ' . $this->pmailer->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
In my library i have this files.
[Library/PHPMailer/]
class.phpmailer.php
class.pop3.php
class.smtp.php
PHPMailerAutoload.php
class.phpmaileroauthgoogle.php

I'm not sure, but you I think this is wrong in your service.php
use Phalcon\PHPMailer;
Change it to
use \PHPMailer as PHPMailer;

Related

error sending email in codeigniter 3 and php 7

$config = [
'protocol' => 'sendmail',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_user' => '***************',
'smtp_pass' => '********',
'smtp_port' => 465,
'smtp_timeout' => '30',
'mailtype' => 'html',
// 'ssl' => [
// 'verify_peer' => false,
// 'veriry_peer_name' => false,
// 'allow_self_sign' => true
// ],// ini hanya jika jaringa tidak ssl/https, jangan dilakukan di produksi
'starttls' => true,
'charset' => 'utf-8',
'newline' => "\r\n"
];
Hi All, I have
I have tried to send mail from my local host but it return error like bellow,
Message: stream_socket_enable_crypto(): SSL/TLS already set-up for this stream
Thank you for your help,
for sending mail from local i'm using SMTP. Please change your code with following code. It's working for me. Do not edit system file. That will create problem for you in future.
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = '********'; //your email id
$config['smtp_pass'] = '********'; //email id password
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

Send email to all the rows from mysql in codeigniter

i need to send emails to all the rows in database table with their corresponsing data. i am able to send single emails by their id, but now i need to send in bulk. i have done in pure php but in codeigniter not able to figure out. how to do this.
my controller is
public function autoformcomplete()
{
$this->load->model('admin/Reminder_model');
$datan = $this->Reminder_model->autoformemail();
//this should be in whileloop, that i am not able to figure out
$email = $datan[0]['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$subject = "Complete Your Partially Filled Application-".$appid."";
$data['datan'] = $datan;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->from('mail#mail.com','My Company');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
echo "sent";
}
My Model is
public function autoformemail(){
$this->db->order_by('id', 'DESC');
$query = $this->db->get('appstbldata');
return $query->result_array();
}
Just use a foreach loop
public function autoformcomplete() {
$this->load->model( 'admin/Reminder_model' );
$datan = $this->Reminder_model->autoformemail();
foreach ( $datan as $index => $val ) {
// $val now references the current pointer to an element in your $datan array
$email = $val['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize( $config );
$this->email->set_mailtype( "html" );
$this->email->set_newline( "\r\n" );
$this->email->set_crlf( "\r\n" );
$subject = "Complete Your Partially Filled Application-" . $appid . "";
$data['datan'] = $datan;
$mesg = $this->load->view( 'email/reminder/form_complete', $data, true );
$this->email->to( $email );
$this->email->from( 'mail#mail.com', 'My Company' );
$this->email->subject( $subject );
$this->email->message( $mesg );
$this->email->send();
echo "sent";
}
}
I dunno what your point of $data['datan'] = $datan; line is though

Fedex SOAP Request Failing

I am looking for the reason why the below request is failing to retrieve information. This is copied from the Fedex developer website and it doesn't work. When my program hits the GetRates line it throws a could not connect to host exception. I tried adding the connection_timeout and setting the default_timeout in php and neither appear to work. I contacted the Fedex dev team and they are receiving my post successfully I am just not able to get any response besides the fault. Has anyone had experience with Fedex or know what might cause this to be failing?
I am posting my current code below. I am using PHP7 on an AS400 machine using Zendserver.
<?php
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 12.0.0
require_once('../library/fedex-common.php5');
$newline = "<br />";
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "../wsdl/RateService_v24.wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
ini_set('soap.wsdl_cache_ttl',0);
$client = new SoapClient($path_to_wsdl, array('trace' => 1, 'connection_timeout' => 30)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
'ParentCredential' => array(
'Key' => getProperty('parentkey'),
'Password' => getProperty('parentpassword')
),
'UserCredential' => array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '24',
'Intermediate' => '0',
'Minor' => '0'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_PRIORITY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING'; // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['RequestedShipment']['TotalInsuredValue']=array(
'Ammount'=>100,
'Currency'=>'USD'
);
$request['RequestedShipment']['Shipper'] = addShipper();
$request['RequestedShipment']['Recipient'] = addRecipient();
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment();
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem1();
try {
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client -> getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR'){
$rateReply = $response -> RateReplyDetails;
echo '<table border="1">';
echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td></tr><tr>';
$serviceType = '<td>'.$rateReply -> ServiceType . '</td>';
if($rateReply->RatedShipmentDetails && is_array($rateReply->RatedShipmentDetails)){
$amount = '<td>$' . number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount,2,".",",") . '</td>';
}elseif($rateReply->RatedShipmentDetails && ! is_array($rateReply->RatedShipmentDetails)){
$amount = '<td>$' . number_format($rateReply->RatedShipmentDetails->ShipmentRateDetail->TotalNetCharge->Amount,2,".",",") . '</td>';
}
if(array_key_exists('DeliveryTimestamp',$rateReply)){
$deliveryDate= '<td>' . $rateReply->DeliveryTimestamp . '</td>';
}else if(array_key_exists('TransitTime',$rateReply)){
$deliveryDate= '<td>' . $rateReply->TransitTime . '</td>';
}else {
$deliveryDate='<td> </td>';
}
echo $serviceType . $amount. $deliveryDate;
echo '</tr>';
echo '</table>';
printSuccess($client, $response);
}else{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
function addShipper(){
$shipper = array(
'Contact' => array(
'PersonName' => 'Sender Name',
'CompanyName' => 'Sender Company Name',
'PhoneNumber' => '9012638716'
),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => 'Collierville',
'StateOrProvinceCode' => 'TN',
'PostalCode' => '38017',
'CountryCode' => 'US'
)
);
return $shipper;
}
function addRecipient(){
$recipient = array(
'Contact' => array(
'PersonName' => 'Recipient Name',
'CompanyName' => 'Company Name',
'PhoneNumber' => '9012637906'
),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => 'Richmond',
'StateOrProvinceCode' => 'BC',
'PostalCode' => 'V7C4V4',
'CountryCode' => 'CA',
'Residential' => false
)
);
return $recipient;
}
function addShippingChargesPayment(){
$shippingChargesPayment = array(
'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => getProperty('billaccount'),
'CountryCode' => 'US'
)
)
);
return $shippingChargesPayment;
}
function addLabelSpecification(){
$labelSpecification = array(
'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PDF', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_7X4.75'
);
return $labelSpecification;
}
function addSpecialServices(){
$specialServices = array(
'SpecialServiceTypes' => array('COD'),
'CodDetail' => array(
'CodCollectionAmount' => array(
'Currency' => 'USD',
'Amount' => 150
),
'CollectionType' => 'ANY' // ANY, GUARANTEED_FUNDS
)
);
return $specialServices;
}
function addPackageLineItem1(){
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => 50.0,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 108,
'Width' => 5,
'Height' => 5,
'Units' => 'IN'
)
);
return $packageLineItem;
}
?>

How to upload file to amazon using filemanager (Responsive Filemanager) in tinymce

How can i upload my file to amazon in filemanager (responsive filemanager) and encrypt it once the image is uploaded.
when using this setup it only save all image on my local folder, any thoughts in this matter?
and when i change my 'curent_path' to 'https://s3-us-west-2.amazonaws.com/dir/subdir/directoryhere it give me error on php
below is my sample code setup,
if (!empty($_SERVER["SERVER_NAME"])) {
$host = $_SERVER["SERVER_NAME"];
} else {
$host = "localhost";
}
$urlParts = explode(".",$host);
$subdomain = $urlParts[1];
if ($subdomain == "tvms") {
$link = "https://s3.amazonaws.com";
$bucket = "tvms-live";
} else {
$link = "https://s3-us-west-2.amazonaws.com";
$bucket = "tvms-uat";
}
define('USE_ACCESS_KEYS', false); // TRUE or FALSE
define('DEBUG_ERROR_MESSAGE', true); // TRUE or FALSE
$config = array(
//'base_url' => ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http"). "://". #$_SERVER['HTTP_HOST'],
'base_url' => $link,
'upload_dir' => '/' . $bucket . '/acvr/uploads/hostedimages/',
'current_path' => '../source/',
'thumbs_base_path' => '../thumbs/',
'mime_extension_rename' => true,
'ftp_host' => false, //put the FTP host
'ftp_user' => "user",
'ftp_pass' => "pass",
'ftp_base_folder' => "base_folder",
'ftp_base_url' => "http://site to ftp root",
// Directory where place files before to send to FTP with final /
'ftp_temp_folder' => "../temp/",
'ftp_thumbs_dir' => '/thumbs/',
'ftp_ssl' => false,
'ftp_port' => 21,
/* EXAMPLE
'ftp_host' => "host.com",
'ftp_user' => "test#host.com",
'ftp_pass' => "pass.1",
'ftp_base_folder' => "",
'ftp_base_url' => "http://host.com/testFTP",
*/
'multiple_selection' => true,
'multiple_selection_action_button' => true,
'access_keys' => array(
'key' =>'AAKJSKDFIOUEJKNRWELNQWEWQE',
'secret' => 'opisdfj2j3kl2n43249sdfijadsf890324'
),
heres the error message

Can't solve the Undefined index: outputBuffering in /vendor/slim/slim/Slim/App.php on line 252 error

I am following the Destructy tutorial and, after setting up and testing out the database connection I get the following error:
So far, this are my settings:
return [
'settings' => [
'displayErrorDetails' => true,
],
'url' => 'http://localhost',
'db' => [
'mysql' => [
'host' => 'localhost',
'dbname' => 'destructy',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]
],
];
This is how the container is defined:
/*Set Slim up*/
$container = new \Slim\Container();//Ver si le afecta o no los paréntesis ()
$container['settings'] = function($c){
return $c['config']->get('settings');
};
$container['config'] = function($c){ //c= current state of our container
return new \Noodlehaus\Config('../config/app.php');//We could pass more parameters ... as an array ['param1','param2','etc']
};
$container['view'] = function($c){//c= current state of our container
$view = new Slim\Views\Twig('../resources/views');//Ubicación de las vistas
//Ability to generate URLs to routes from within our views
$view->addExtension(new \Slim\Views\TwigExtension(
$c['router'],
$c['config']->get('url')
));
return $view;
};
//base de datos:
$container['db'] = function($c){
//return new PDO('mysql:host=127.0.0.1;dbname=destructy','root','root');
return new PDO(
'mysql:host='.$c['config']->get('db.mysql.host').';dbname='.$c['config']->get('db.mysql.dbname'),
$c['config']->get('db.mysql.username'),
$c['config']->get('db.mysql.password'));
};
$app = new Slim\App($container);
require_once 'routes.php';
The route:
$app->get('/',function($request,$response,$args){
echo 'Destructy - Home.';
echo '<p style="color: darkblue">Welcome to the admin area</p>';
echo '<p>Testing access to config parameters ...</p>';
echo $this->config->get('db.mysql.host').'<br>';
echo $this->config->get('url');
/*Testing out DB connection*/
var_dump($this->db);
$this->view->render($response,'home.twig');
});
$app->run();
Does anybody know what the problem is in order to fix it?
You're not able to use the dot syntax to access the config values, should be something like:
$container['db'] = function($c){
$conf = $c->db;
return new PDO(
'mysql:host='.$conf['mysql']['host'].';dbname='.$conf['mysql']['dbname'],
$conf['mysql']['username'],
$conf['mysql']['password'];
};