bootstrap mail form $from<$email> $fromEmail - mail-form

I refer to this page. https://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form and i uesd index-2.html / contact-2.php files.
i want mailheader ''
but code is
**$fromEmail = 'demo#domain.com';
$fromName = 'Demo contact form';**
$sendToEmail = 'my#mail.com';
$fields = array('name' => 'Name', 'phone' => 'Phone', 'email' => 'Email', "\r\n" , 'message' => 'Message');
so i changed
$fromEmail = "$email" $fromName = '$name'; or
$fromEmail = $_POST['form_email']; $name = $_POST['name'];
but It just makes an error.
ex) Root User" '
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailTextHtml .= "<table>";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailTextHtml .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
}
}
$emailTextHtml .= "</table>";
$mail = new PHPMailer;
$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($sendToEmail, $sendToName); // you can add more addresses by simply adding another line with $mail->addAddress();
$mail->addReplyTo($from);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->msgHTML($emailTextHtml); //
what should I do?
$fromEmail = 'demo#domain.com';
$fromName = 'Demo contact form'
How should I change it?

Related

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

attachment is not sent in email in CodeIgniter [duplicate]

I am trying to send email on codeigniter with attach file.
I always receive email successfully. However , I never receive with attach file. Below is code and highly appreciate for all comments.
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "test#gmail.com";
$config['smtp_pass'] = "test";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('test#test.com', 'Test Email');
$list = array('test2#gmail.com');
$ci->email->to($list);
$this->email->reply_to('my-email#gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->attach( '/test/myfile.pdf');
$ci->email->send();
$this->email->attach()
Enables you to send an attachment. Put the file path/name in the first parameter. Note: Use a file path, not a URL. For multiple attachments use the function multiple times. For example:
public function setemail()
{
$email="xyz#gmail.com";
$subject="some text";
$message="some text";
$this->sendEmail($email,$subject,$message);
}
public function sendEmail($email,$subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'abc#gmail.com',
'smtp_pass' => 'passwrd',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('abc#gmail.com');
$this->email->to($email);
$this->email->subject($subject);
$this->email->message($message);
$this->email->attach('C:\Users\xyz\Desktop\images\abc.png');
if($this->email->send())
{
echo 'Email send.';
}
else
{
show_error($this->email->print_debugger());
}
}
i have this problem before , the problem with the path file , so i change the path file to
$attched_file= $_SERVER["DOCUMENT_ROOT"]."/uploads/".$file_name;
$this->email->attach($attched_file);
And it works fine with me
With Codeigniter 3.1.0 I had same problem. Seems that there is missing a "\r\n":
Content-Type: application/pdf; name="test.pdf"<br>
Content-Disposition: attachment;<br>
Content-Transfer-Encoding: base64<br>
JVBERi0xLjYNJeLjz9MNCjQzNyAwIG9iag08PC9MaW5lYXJpemVkIDEvTCA3OTUyMTYvTyA0Mzkv<br>
RSA2ODEwODcvTiA0L1QgNzk0ODA3L0ggWyA1NjQgMjYxXT4+DWVuZG9iag0gICAgICAgICAgICAg<br>
should be:
Content-Type: application/pdf; name="test.pdf"<br>
Content-Disposition: attachment;<br>
Content-Transfer-Encoding: base64<br>
<br>
JVBERi0xLjYNJeLjz9MNCjQzNyAwIG9iag08PC9MaW5lYXJpemVkIDEvTCA3OTUyMTYvTyA0Mzkv<br>
RSA2ODEwODcvTiA0L1QgNzk0ODA3L0ggWyA1NjQgMjYxXT4+DWVuZG9iag0gICAgICAgICAgICAg<br>
I changed line 725 in system/libraries/Email from
'content' => chunk_split(base64_encode($file_content)),<br>
to
'content' => "\r\n" . chunk_split(base64_encode($file_content)),<br>
It works for me, but not the perfect fix.
Try putting the full path in $ci->email->attach();
On windows this would like something like
$ci->email->attach('d:/www/website/test/myfile.pdf');
This method has worked well for me in the past.
If you want to send attachment in email Without uploading file on server, please refer below.
HTML View file
echo form_input(array('type'=>'file','name'=>'attach_file','id'=>'attach_file','accept'=>'.pdf,.jpg,.jpeg,.png'));
Controller file
echo '<pre>'; print_r($_FILES); shows below uploaded data.
[attach_file] => Array
(
[name] => my_attachment_file.png
[type] => image/png
[tmp_name] => C:\wamp64\tmp\php3NOM.tmp
[error] => 0
[size] => 120853
)
We will use temporary upload path [tmp_name] where attachment is uploaded, because we DO NOT want to upload attachment file on server.
$this->email->clear(TRUE); //any attachments in loop will be cleared.
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
//Check if there is an attachment
if ( $_FILES['attach_file']['name']!='' && $_FILES['attach_file']['size'] > 0 )
{
$attach_path = $_FILES['attach_file']['tmp_name'];
$attach_name = $_FILES['attach_file']['name'];
$this->email->attach($attach_path,'attachment',$attach_name);
}
$this->email->send();
use path helper
$this->load->helper('path');
$path = set_realpath('./images/');
on email line
$this->email->attach($path . $your_file);
here i am using phpmailer to send mail
here full code is mention below
$this->load->library('My_phpmailer');
$mail = new PHPMailer();
$mailBody = "test mail comes here2";
$body = $mailBody;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1;// enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true;// enable SMTP authentication
$mail->Host = "ssl://smtp.gmail.com"; // sets the SMTP server
$mail->Port = 465;// set the SMTP port for the GMAIL server
$mail->Username = "YourAccountIdComesHere#gmail.com"; // SMTP account username
$mail->Password = "PasswordComesHere";// SMTP account password
$mail->SetFrom('SetFromId#gmail.com', 'From Name Here');
$mail->AddReplyTo("SetReplyTo#gmail.com", "Reply To Name Here");
$mail->Subject = "Mail send by php mailer";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment($cdnStorage . '/' . $fileName);
$address ='WhomeToSendMailId#gmail.com';
$mail->AddAddress($address, "John Doe");
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Here Is Full Source Code
$validation_rules = array(
array('field' => 'name', 'rules' => COMMON_RULES),
array('field' => 'email', 'rules' => COMMON_RULES),
array('field' => 'message', 'rules' => COMMON_RULES),
);
$this->validation_errors($validation_rules);
$name = $this->input->post('name');
$email = $this->input->post('email');
$message = $this->input->post('message');
$this->load->library('email');
//upload file
$attachment_file = "";
if (!empty($_FILES) && isset($_FILES["attachment_file"])) {
$image_name = $_FILES["attachment_file"]['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);
$new_name = time() . '_' . $this->get_random_string();
$config['file_name'] = $new_name . $ext;
$config['upload_path'] = "uploads/email/";
$config['allowed_types'] = "*";
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('attachment_file')) {
$finfo = $this->upload->data();
$attachment_file = base_url() . 'uploads/email/' . $finfo['file_name'];
} else {
$error = $this->upload->display_errors();
$this->msg = $error;
$this->_sendResponse(5);
}
}
$this->email->from($email, "$name")
->to("example#gmail.com")
->subject("FeedBack From $name")
->message($message)
->attach($attachment_file);
if ($this->email->send()) {
// temp pass updated.
$this->msg = "Email send successfully.";
$this->_sendResponse(1);
} else {
$this->msg = "Internal server error/Something went wrong.";
$this->_sendResponse(0);
}
$this->load->library('email'); // Loading the email library.
$this->email->clear(TRUE);
$this->email->from($user_email, $name);
$this->email->to('email#gmail.com');
$this->email->subject("Some subject");
$this->email->message("Some message");
if($_FILES['userfile']['name']!='' && $_FILES['userfile'['size'] > 0){
$attach_path = $_FILES['userfile']['tmp_name'];
$attach_name = $_FILES['userfile']['name'];
$this->email->attach($attach_path,'attachment',$attach_name);
}
$this->email->send();

Why was the mail sent but not received in zend framework?

I'm new to the zend framework.
I have a code to send a mail and it's working, but the message is not received by the customer side, but it returns that the mail was sent successfully. Can you teach me how to work with zend_email?
public function sendMailStatements($qid,$emails=array()) {
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
try {
$config = array('ssl' => 'ssl',
'port' => 465,
'auth' => 'login',
'host' => '127.0.0.1',
'username' => 'username#gmail.com',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($transport);
$mail = new Zend_Mail();
$mail->setSubject("Quotation LL Sports Exim");
$body="Dear Sir/Madam<br>Kindly find the attached Quotation and give us your Feed BAck";
$mail->setBodyHtml($body);
foreach ($emails as $email):
$mail->addTo($email);
endforeach;
var_dump($emails);
if($qid!=""):
$fullBaseUrl = getcwd();
$full_path = $fullBaseUrl . "\\pdfs\\" .$qid.".pdf";
$content = file_get_contents($full_path); // e.g. ("attachment/abc.pdf")
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename ="quotation.pdf"; // name of file
$mail->addAttachment($attachment);
endif;
$mail->send($transport);
return true;
} catch (Zend_Exception $e) {
echo "Caught exception: " . get_class($e) . "\n";
echo "Message: " . $e->getMessage() . "\n";
exit;
// Other code to recover from the error
}
}
Please let me know where I did wrong?
Thanks in advance.

How to set multiple CC email recipients one message using webform in drupal 7

My website using webform in drupal 7 application.
I have two queries
I can added a list for To email recipients one message. Email will receiving all the recipients but mails sending individual. I cant see in the to list group.
How to set multiple CC email recipients one message ? Here am using 'CC' => 'xx#yyyy.com, xx1#yyyy1.com, xx2#yyyy2.com' in theme_mail_headers under "$headers.
function MODULENAME_mail($key, &$message, $params) {
if($key === 'MODULEcase') {
$header = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal',
'Cc' => implode(',', $params['Cc']),
);
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
foreach ($headers as $key => $value) {
$message['headers'][$key] = $value;
}
break;
}
}
Then prepare data and pass to drupal_mail function
$mail_content = "Hello There!";
$params = array('body' => $mail_content);
$params['cc'] = array(
'cc_user1#example.com',
'cc_user2#example.com',
'cc_user3#example.com',
);
$to = 'touser#example.com';
$from = 'no-reply#example.com';
$mail = drupal_mail('MODULENAME', 'MODULEcase', $to, language_default(), $params, $from);
This is it. Enjoy :-)

Zend-Image Uploading at Wrong Destination

please help..I'm newbies and try to learn Zend Framework, but have problem when uploading image.
The script at file Application.ini
uploads.uploadPath = APPLICATION_PATH "/../public/uploads"
Form to upload Image:
$this->setAction('/data/personil/create')
->setMethod('post');
//Item input untuk gambar
$images = new Zend_Form_Element_File('images');
$images->setMultiFile(3)
->addValidator('IsImage')
->addValidator('Size', false, '204800')
->addValidator('Extension', false, 'jpg,png,gif')
->addValidator('ImageSize', false, array(
'minwidth' => 150,
'minheight' => 150,
'maxwidth' => 700,
'maxheight' => 700
))
->setValueDisabled(true);
// attach element to form
$this->addElement($images);
// create display group for file elements
$this->addDisplayGroup(array('images'), 'files');
$this->getDisplayGroup('files')
->setOrder(40)
->setLegend('Images');
Controller action create :
public function createAction()
{
$form = new Pengadilan_Form_PersonilCreate();
$this->view->form = $form;
$flashMessenger = $this->_helper->FlashMessenger;
//SImpan kedatabase
if($this->getRequest()->isPost()){
if($form->isValid($this->getRequest()->getPost())){
$personil = new Pengadilan_Model_Personil();
$personil->fromArray($form->getValues());
$personil->RecordDate = date('Y-m-d', mktime());
$personil->DisplayStatus = 0;
$personil->DisplayUntil = null;
$personil->save();
$id = $personil->RecordId;
$config = $this->getInvokeArg('bootstrap')->getOption('uploads');
$form->images->setDestination($config['uploadPath']);
$adapter = $form->images->getTransferAdapter();
for($x=0; $x<$form->images->getMultiFile(); $x++) {
$xt = #pathinfo($adapter->getFileName('images_'.$x.'_'), PATHINFO_EXTENSION);
$adapter->clearFilters();
$adapter->addFilter('Rename', array(
'target' => sprintf('%d_%d.%s', $id, ($x+1), $xt),
'overwrite' => true
));
$adapter->receive('images_'.$x.'_');
}
$this->_helper->getHelper('FlashMessenger')->addMessage('Data sekses diinput ke database #' . $id . '. Admin akan segera merivew, jika diterima, akan ditampilkan dalam waktu 48 jam, Terima kasih.');
$this->_redirect('/data/personil/sukses');
}
}
}
Controller action display :
public function displayAction()
{
//Pertama setting filters
$filters = array(
'id' => array('HtmlEntities', 'StripTags', 'StringTrim')
);
$validators = array(
'id' => array('NotEmpty', 'Int')
);
$input = new Zend_Filter_Input($filters, $validators);
$input->setData($this->getRequest()->getParams());
if($input->isValid()){
$q = Doctrine_Query::create()
->from('Pengadilan_Model_Personil p')
->leftJoin('p.Pengadilan_Model_Jabatan j')
->leftJoin('p.Pengadilan_Model_Tupoksi t')
->leftJoin('p.Pengadilan_Model_Golongan g')
->leftJoin('p.Pengadilan_Model_Agama a')
->leftJoin('p.Pengadilan_Model_Kelamin k')
->where('p.RecordId = ?', $input->id)
->addWhere('p.DisplayStatus = 1')
->addWhere('p.DisplayUntil >= CURDATE()');
$result = $q->fetchArray();
if(count($result) == 1){
$this->view->personil = $result[0];
$this->view->images = array();
$config = $this->getInvokeArg('bootstrap')->getOption('uploads');
foreach (glob("{$config['uploadPath']}/{$this->view->item['RecordID']}_*") as $file) {
$this->view->images[] = basename($file);
}
}else{
throw new Zend_Exception('Maaf, halaman tidak ditemukan, 404');
}
}else{
throw new Zend_Exception('Kesalahan Input');
}
}
The last script at view : display.phtml
<div id="images">
<?php foreach ($this->images as $image): ?>
<img src="/uploads/<?php echo $this->escape($image); ?>" width="150" height="150" />
<?php endforeach; ?>
Image upload Destination at config is /public/uploads
in my case image at /public
Image succes to upload and renamed but outside the directory and
Image won't displayed at display.phtml
Many thanks for your help..
First you need to set your form encoding File element link$form->setAttrib('enctype', 'multipart/form-data');
Also you should probably finish setting up your image element before you POST the form not after. So move the setDestination stuff up to where you initialize the form, you may have a better chance of it working.
public function createAction()
{
$form = new Pengadilan_Form_PersonilCreate();
//set form encoding
$form->setAttrib('enctype', 'multipart/form-data');
//get path and set destination for image element
$config = $this->getInvokeArg('bootstrap')->getOption('uploads');
$form->images->setDestination($config['uploadPath']);
$this->view->form = $form;
//consider intializing flash messenger in the init() method
$flashMessenger = $this->_helper->FlashMessenger;
//SImpan kedatabase
if($this->getRequest()->isPost()){
if($form->isValid($this->getRequest()->getPost())){
//more code...
$adapter = $form->images->getTransferAdapter();
for($x=0; $x<$form->images->getMultiFile(); $x++) {
$xt = #pathinfo($adapter->getFileName('images_'.$x.'_'), PATHINFO_EXTENSION);
$adapter->clearFilters();
$adapter->addFilter('Rename', array(
'target' => sprintf('%d_%d.%s', $id, ($x+1), $xt),
'overwrite' => true
));
$adapter->receive('images_'.$x.'_');
}
$this->_helper->getHelper('FlashMessenger')->addMessage('Data sekses diinput ke database #' . $id . '. Admin akan segera merivew, jika diterima, akan ditampilkan dalam waktu 48 jam, Terima kasih.');
$this->_redirect('/data/personil/sukses');
}
}
}
not sure if this will fix everything but it should be a start...