How can add email signature in codeigniter? - php

I have a codeigniter function to send emails.Its working fine,but the only problem is email signature id not adding to my email. I am using gmail to send email. i set email signature in gmail configuration.
How can add email signature in codeigniter?

You can use views for this
// views/email_message.php
<?php echo $this->load->view('email/message', $message_data(), TRUE) ?>
<?php echo $this->load->view('email/signature', $signature_data(), TRUE) ?>
and then you can pass this to your email message:
// in your controller
$message = $this->load->view('views/email_message', $data(), TRUE);
// configure email options, etc.
...
$this->email->message($message);
// send the email

Related

Why is the email is not send in this code? Magento

I am trying to send a email for a user when he fill a form and click the submit.I have created a controller in Magento and included the following code
public function sendMailAction(){
$html="put your html content hereblah blah";
$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('sadeeenadeee#gmail.com');
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// YOu can use Html or text as Mail format
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
$this->_redirect('');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
$this->_redirect('');
}
}
This is the function I am planning to use to send the email.Above controller function is called for the click of the submit button.
Then I configured the outgoing SMTP email in Magento admin panel.
System > Configuration-> Mail Sending Settings
I followed the above path and added the HOST and PORT in the Mail Sending Settings and saved the config.HOST and PORT are obtained from the email service provider.But when a user fills the form and click the submit,rather than sending a email browser tries to launch a app saying that,
THIS LINK NEEDS TO BE OPEN WITH AN APPLICATION
Can someone help me please?
I AM WORKING ON A HOSTED SITE
$emailTemplateVariables = array();
$EmailSenderName="Email Sender Name";
$EmailId="semder Email";
$emailTemplateVariables['key1'] = "data1";
$emailTemplateVariables['key2'] = "data2";
/* sent mail to //recepient */
$recipientEmail="abcd#xyz.com";
$sender = Array('name' => $EmailSenderName,
'email' => $EmailId);
$emailName = 'Email Name';
$translate = Mage::getSingleton('core/translate');
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('Any_email_template');
$emailTemplate->setSenderName($EmailSenderName)
->setSenderEmail($EmailId)
->setTemplateSubject($emailName);
$emailstatus=$emailTemplate->send($recipientEmail, $emailName, $emailTemplateVariables);
$translate->setTranslateInline(true);
if($emailstatus) {
//email send successfully
}
else {
//something went wrong
}
Please confirm that any mails in que for that enter the terminal command
mailq
$emailTemplate = Mage::getModel('core/email_template')->load(1); //1 is Transactional Emails id
if you want to try default the above

A simple email client/contact form is returning a "5.5.4 Invalid Domain Error" and I have exhausted all my resources attempting to solve it

I've posted this question twice in the last two days and I have really run dry of solutions. I'm creating a very simple comment box that when filled out sends the comment in an email to my company's safety department. I have been receiving this 5.5.4 Invalid Domain Error for the last couple days.
It's SMTP and TLS. The port and server name is correct. The server allows for anonymous emails, and does not validate. I'm using the Swiftmailer library so I shouldn't need to script a ELHO/HELO. The only property of the email that's not defined/hard coded is the body of the message. This is the code for my controller (index.php).
// Initialize Swiftmailer Library
require_once("./swiftmailer/lib/swift_required.php");
// Class that contains the information of the email that will be sent (from, to, etc.)
require_once("./classes/EmailParts.php");
// The class that "breaks" the data sent with the HTML form to a more "usable" format.
require_once("./classes/ContactForm.php");
// =====================
// Main Configuration
// =====================
define("EMAIL_SUBJECT", "Safety Concerns");
define("EMAIL_TO", "safetydepartment#company.com");
define("EMAIL_FROM", "safetydepartment#company.com");
// SMTP Configuration
define("SMTP_SERVER", 'exchange.company.local');
define("SMTP_PORT", 25);
function main($contactForm) {
// Checks if something was sent to the contact form, if not, do nothing
if (!$contactForm->isDataSent()) {
return;
}
// Validates the contact form and checks for errors
$contactForm->validate();
$errors = array();
// If the contact form is not valid:
if (!$contactForm->isValid()) {
// gets the error in the array $errors
$errors = $contactForm->getErrors();
} else {
// If the contact form is valid:
try {
// send the email created with the contact form
$result = sendEmail($contactForm);
// after the email is sent, redirect and "die".
// We redirect to prevent refreshing the page which would resend the form
header("Location: ./success.php");
die();
} catch (Exception $e) {
// an error occured while sending the email.
// Log the error and add an error message to display to the user.
error_log('An error happened while sending email contact form: ' . $e->getMessage());
$errors['oops'] = 'Ooops! an error occured while sending your email! Please try again later!';
}
}
return $errors;
}
// Sends the email based on the information contained in the contact form
function sendEmail($contactForm) {
// Email part will create the email information needed to send an email based on
// what was inserted inside the contact form
$emailParts = new EmailParts($contactForm);
// This is the part where we initialize Swiftmailer with
// all the info initialized by the EmailParts class
$emailMessage = Swift_Message::newInstance()
->setSubject($emailParts->getSubject())
->setFrom($emailParts->getFrom())
->setTo($emailParts->getTo())
->setBody($emailParts->getBodyMessage());
// Another Swiftmailer configuration..
$transport = Swift_SmtpTransport::newInstance(SMTP_SERVER, SMTP_PORT, 'tls');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($emailMessage);
return $result;
}
// Initialize the ContactForm with the information of the form and the possible uploaded file.
$contactForm = new ContactForm($_POST, $_FILES);
// Call the "main" method. It will return a list of errors.
$errors = main($contactForm);
// Call the "contactForm" view to display the HTML contact form.
require_once("./views/contactForm.php");
I've posted the entirety of my code at Dropbox. There's not much, but I think the problem must lie in the Index.

Using a HTML Mail template with codeigniter

I am using the codeigniter email class to send emails when the user register to my website or perform some activity inside my website.
The thing is that, with this simple code below I can only send very simple HTML emails. And also I will have to pass the entire HTML message to the function. Is there any way so that I could load the entire template in the function itself and just pass a message which is to be placed inside the template as we do in codeigniter with views.
$message = 'Thank you for your order \n';
$message .= 'We will contact you soon';
$this->email($message);
public function email($message = NULL){
$this->load->library('email');
$this->email->mailtype('html');
$this->email->from('abbbba#gmail.com', 'Sohan Kc');
$this->email->to('abbbbaa#gmail.com');
$this->email->subject('Email Test');
$this->email->message($message);
$this->email->send();
}
Why don't you just do as you already stated? :)
The email classes message method requires a string to be passed. Just load a View and pass the returned string to the method.
public function email($message = NULL){
$this->load->library('email');
$mydata = array('message' => 'I am a message that will be passed to a view');
$message = $this->load->view('my_email_template', $mydata, true);
$this->email->mailtype('html');
$this->email->from('sohanmax2#gmail.com', 'Sohan Kc');
$this->email->to('sohanmax02#gmail.com');
$this->email->subject('Email Test');
$this->email->message($message);
$this->email->send();
}
I send emails but got the html code as body, I had to add the headers to get correct content like below and it will works out.
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');

Codeigniter email verification pass parameters

I am trying to implement an email verification after registering an account. So after registering an account, an email will be sent to the user email to verify. the email was sent using the email class of codeigniter.
The code for sending the email is as below
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('admin#mathplication.com', 'admin');
$this->email->to($user_email);
$this->email->subject('Registration verification for mathplication');
$this->email->message('
Thanks for signing up!
Your account has been created, you can login with the following credentials
after you have activated your account by pressing the url below.
Please click this link to activate your account:
<a href='.base_url('verify').'?email='.$user_email.'&rand='.$user_rand.'>Click Here</a>');
$this->email->send();
and in the routes.php in the config folder
$route['verify'] = "login_register/view_verify
in which view_verify is the function in my login_register controller
inside this view_verify I will check the two parameters I passed which are the email and the random string generated.
function view_verify($email,$rand)
{
//$email = $this->input->get('email');
//$rand = $this->input->get('rand');
$this->load->database();
$this->load->model('login_model');
$result= $this->login_model->email_verification($email,$rand);
if($result==TRUE)
{
$this->load->view('pages/verify');
}
}
I will get a 404 page not found error. Not sure if my routing with the variables is the problem here or not or is there another way of passing parameters through url to the controller. Thanks in advance for the help.
If you are going to be using query strings in the url, you will need to enable that in the config. Possible there might also be issues with permitted_uri_chars because of the email address.
You could generate the url with the user id and nonce like:
<a href='.base_url('verify').$user_id.'/'.$user_rand.'>Click Here</a>');
Which should produce something like
http://www.example.com/verify/1234/23q23rq2rq24rq34rq34rq34r
Then in routes:
$route['verify/(:any)'] = "login_register/view_verify/$1";
At this point the function view_verify should work correctly exactly as it is now except you will need to adjust your model to do the lookup via user id instead of by email.
function verify($verificationText=NULL){
$noRecords = $this->HomeModel->verifyEmailAddress($verificationText);
if ($noRecords > 0){
$error = array( 'success' => "Email Verified Successfully!");
}else{
$error = array( 'error' => "Sorry Unable to Verify Your Email!");
}
$data['errormsg'] = $error;
$this->load->view('index.php', $data);
}

Using Email Class in Codeigniter (Advanced Way)

I want to send emails using Email Class(CodeIgniter) Problem is that
Email is sending so simple in text format...
I want to design email with (html, tables and colors) or What is the advanced-way for Emailing with CodeIgniter.
function signup(){
#stripped out the validation code
#stripped out the db insert code
$data = array(
'some_var_for_view'=>'Some Value for View'
);
$htmlMessage = $this->parser->parse('user/email/signup_html', $data, true);
$txtMessage = $this->parser->parse('user/email/signup_txt', $data, true);
#send the message
$this->email->from('test#webdevkungfu.com', 'CSSNinja');
$this->email->to($this->input->post('email_address'));
$this->email->subject('Account Registration Confirmation');
$this->email->message($htmlMessage);
$this->email->alt_message($txtMessage);
$this->email->send();
}
My problem is now solved with this code found from link below
http://www.webdevkungfu.com/email-templates-with-codeigniter/

Categories