I've created a sending of email using codeigniter. on the past months it was working fine. When I checked it again it doesn't send emails anymore.
Here's My code:
public function send_mail($registration_info_id){
$config_mail = $this->main_m->get_all('emails');
$all_mails="";
foreach($config_mail as $email){
$all_mails.= $email['email'].',';
}
$supply_email = rtrim($all_mails,",");
$registration_info = $this->main_m->get_where('registration_info', array('registration_info_id' => $registration_info_id));
$personal_info = $this->flight_travel_request_m->personal_info_per_person($registration_info_id);
$cc_details = $this->main_m->get_where('payment_credit_card_details', array('registration_info_id' => $registration_info_id));
$full_name = $personal_info['firstname']." ".$personal_info['lastname'];
$data = array(
'registration_info' => $registration_info,
'personal_info' => $personal_info,
'cc_details' => $cc_details
);
//$this->load->view('email_acknowledgement/acknowledgement', $data);
$message=$this->load->view('email_acknowledgement/acknowledgement', $data, true);
$this->load->library('email');
$this->email->from('sample#site.com', 'SiteName');
$this->email->to($personal_info['email'], $full_name);
$this->email->reply_to('sample#site.com', 'SiteName');
$this->email->bcc($supply_email);
$this->email->subject('Arrival Departure Transportation Service');
$this->email->message($message);
if(!empty($attachment)){$this->email->attach($attachment);}
$this->email->set_mailtype('html');
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
it echoes the Email Sent however I cant receive any email on my email address.
it was working fine previously.
Thanks in advance
Please try it.
$config['protocol'] = 'smtp';
$config['validate'] = 'FALSE';
I hope that works for you
And see this link Codeigniter $this->email->send() not working while mail() does
Related
I have created a custom registration form in Drupal 8, and now i want to sent a mail from the submission of the form. So I have did it like this
This is my .module file
/**
* Implements hook_mail().
*/
function Registration_form_mail($key, &$message, $params) {
$options = array(
'langcode' => $message['langcode'],
);
switch ($key) {
case 'contact_form':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
break;
}
}
public function submitForm(array &$form, FormStateInterface $form_state){
$mailManager = \Drupal::service('plugin.manager.mail');
$module = 'Registration_form';
$key = 'contact_form'; // Replace with Your key
$to = $form_state->getValue('Email');
$params = array(
'body' => 'test',
'subject' => 'Website Information Request',
);
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$send = true;
$message['subject'] = t('nouveau contact ');
$message['body'][] = t('test');
$result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send);
if ($result['result'] != true) {
$message = t('There was a problem sending your email notification to #email.', array('#email' => $to));
drupal_set_message($message, 'error');
\Drupal::logger('mail-log')->error($message);
return;
}
else{
$message = t('An email notification has been sent to #email ', array('#email' => $to));
drupal_set_message($message);
\Drupal::logger('mail-log')->notice($message);
}
}
So my question is i'm using localhost in xampp and i want to sent a mail after submission of the form, but i'm getting this error
Unable to send email. Contact the site administrator if the problem persists.
There was a problem sending your email notification to ABC#gmail.com
So how I can resolve my problem, i have gone through whole sites but not able to find answer.
The problem may be with the email configuration. See if this article helps you:
https://stevepolito.design/blog/drupal-configure-smtp-module-work-gmail-updated/
i trying to develop a user management system.In here i send an email to user when his account has been created. Now i also want to send an email to him when his status has been activated. For this i used this :
$data = $this->reseller_m->array_from_post(array('sip_username','sip_password','key','allocation_block','name','email','password','phone','balance','user_num','address','country','country_code','created','modified','status'));
$data['password'] = $this->reseller_m->hash($data['password']);
$key=$this->reseller_m->save($data, $id);
if($id === NULL)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.temp.com',
'smtp_port' => 25,
'smtp_user' => 'temp#temp.com',
'smtp_pass' => 'temp#1234',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('temp#bizrtc.com', 'Rajan');
$this->email->to($_POST['email']);
$this->email->subject('Your Account Has Been SuccessFully Created.');
$this->email->message('Hi, We have created your Account. Please Login : crm/reseller/secure/login');
$this->email->send();
if ($this->email->send())
{
echo"Success";
}
else
{
echo '<p class="error_msg">That Email And Password Combination Does Not Exist!</p>';
}
}
$result = $this->reseller_m->check_mail_status($id);
if($result[0]['email_send']==0)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.temp.com',
'smtp_port' => 25,
'smtp_user' => 'temp#temp.com',
'smtp_pass' => 'temp#1234',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('temp#bizrtc.com', 'Rajan');
$this->email->to($_POST['email']);
$this->email->subject('Your Account Has Been SuccessFully Activated.');
$this->email->message('Hi, We have created your Account. Please Login ');
$this->email->send();
if ($this->email->send())
{
echo"Success";
}
else
{
echo '<p class="error_msg">That Email And Password Combination Does Not Exist !</p>';
}
}
else
{
echo "Error 123";
die();
}
This works perfectly but this function is in my edit method so whenever i edit a user it again takes status as post= active and sends mail everytime i edit him. I want to only send an email when his status is changed from active to inactive or vice versa. My edit method checks if i have an id. If I have then edit a user or else create a new.
Yes it does. Every time when function triggered mail will sent.
Follow these steps
Use database field with email_send vales with 0 and 1.
0 == no mail sent and 1 == for mail sent.
Before send check whether valve us == 0 then only send mail.
if email_send == 0 send mail and update database with 1
EDIT 01
In controller
<?
if($_POST['status'] === 'Active')
{
// retrieve user id and assign to $id
$result = $this->Model_name->check_mail_status($id);
if($result[0]['email_send']==0)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.temp.com',
'smtp_port' => 25,
'smtp_user' => 'temp#temp.com',
'smtp_pass' => 'temp#1234',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('temp#test.com', 'Rajan');
$this->email->to($_POST['email']);
$this->email->subject('Your Account Has Been SuccessFully Activated.');
$this->email->message('Hi, We have created your Account. Please Login ');
$this->email->send();
if ($this->email->send())
{
echo"Success";
}
else
{
echo '<p class="error_msg">That Email And Password Combination Does Not Exist !</p>';
}
}
else
{
echo '<p class="error_msg">Mail sent already</p>';
}
}
?>
In Model
function check_mail_status($id)
{
$this->db->select('*');
$this->db->where('id', $id );
$query = $this->db->get('mytable');
$result = $query->result_array();
return $result;
}
Edit 02
alter this in controller code
if ($this->email->send())
{
$this->Model_name->update_email_send($id);
}
In model
function update_email_send($id)
{
$data = array(
'email_send' => 1
);
$this->db->where('id', $id);
$this->db->update('mytable', $data);
}
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.
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'
),
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.)