I am working on a project that needs to send email.I use this as my controller
$from_email = $this->input->post('email');
$to_email = "info#test.com";
$name = $this->input->post('name');
$phno = $this->input->post('phno');
$from = $this->input->post('start');
$to = $this->input->post('end');
$message = $this->input->post('message');
$bodyContent="<table>
<tr><td>Name:</td><td>$name</td></tr>
<tr><td>Phno:</td><td>$phno</td></tr>
<tr><td>From Date:</td><td>$from</td><td>To Date:</td><td>$to</td></tr>
<tr><td>Message:</td><td>$message</td></tr>
</table>";
//Load email library
$this->load->library('email');
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject('Enquiry From Test TOURS');
$this->email->message($bodyContent);
//Send mail
if($this->email->send()) {
$this->session->set_flashdata("email_sent","Email sent successfully.");
} else {
$this->session->set_flashdata("email_sent","Error in sending Email.");
}
redirect('test_view/index');
And I am getting the output in the mail as like this
<table>
<tr><td>Name:</td><td>wer</td></tr>
<tr><td>Phno:</td><td>wer</td></tr>
<tr><td>From Date:</td><td>10/18/2017</td><td>To
Date:</td><td>10/25/2017</td></tr>
<tr><td>Message:</td><td>wer</td></tr>
</table>
I don't know why i am getting output in the mail like this , can anyone sortout this error please.
use mailtype configuration 'html' in Email configuration file
$config['mailtype'] = 'html';
from user guide
You need to set the type as html :
$this->email->set_mailtype("html");
Related
Have tried send email to multiple recipients but only 1 data is sent:
function reminder(){
$recipients= $this->user_model->view();
var_dump($recipients[0]->email);
$emaill = $recipients->email;
$recipientsmail= $emaill.',';
$email = $recipientsmail;
$judul = 'Test Email';
$deskripsi = 'TESt Email';
$config = [...]; //config for email is OK
$this->load->library('email', $config);
$this->email->from('tes');
$this->email->to($email);
$this->email->subject($judul);
$this->email->message($deskripsi);
$this->email->send();
return TRUE;
}
is something wrong in my code?
Please Help Me
That's the way I use to send multiple emails in codeigniter. Instead of put all the email directions in a variable ($email), use a foreach to loop the array and follow the details in the code:
function reminder(){
$recipients= $this->user_model->view();
var_dump($recipients[0]->email);
$judul = 'Test Email';
$deskripsi = 'This is a test';
$emailuser = 'user123#gmial.com';//for example
$nameuser = 'name of the user';
$config = [...]; //config for email is OK
$this->load->library("email");
foreach ($recipients as $value) {
$this->email->initialize($config);
$this->email->from($emailuser, $nameuser);
$this->email->to($value->email);
$this->email->subject($judul);
$this->email->message($deskripsi);
if($this->email->send()){
$this->session->set_flashdata("email_sent","Email sent successfully.");
}else{
$this->session->set_flashdata("email_sent","Error in sending Email.");
}
}
return TRUE;
}
And with this you could send more than one email. I hope it helps you.
I am usng bluehost as server of my domain. I am using below code for sending mail using PHPMailer. The code does not through error and confirms that the mail has gone. But actually the mail does not go to recipient. can anyone suggest what is wrong here?
$Recpnt1='abc#gmail.com';
$emailfrom = 'xyz#AlphaBeta.com';
require_once 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
//From email address and name
$mail->From = $emailfrom;
$mail->FromName = "AlphaBeta";
//To address and name
$mail->addAddress($Recpnt1);
//Send HTML or Plain Text email
$mail->isHTML(true);
// Your subject
$mail->Subject = "Your confirmation link here";
$message='ABCD';
$mail->Body = $message;
if($mail->send())
{
$error = $error . "Confirmation link Has Been Sent To Your Email Address.";
}
else
{
$error = $error . 'Cannot send Confirmation link to your e-mail address';
}
We are using amazon server and I am using PHP, Codeigniter framework.
Below is the script which I am using for sending emails.
It is working when I send an email to Gmail domain email id (abc#gmail.com) but it is not working on some specific domain name email id (abc#xyzdmainname.com).
public function sendMail() {
$to = 'abc#xyzdomain.com';
$fromEmail = 'pqr#gmail.com';
$fromName = 'pqr';
$subject = 'Testing';
$message = 'Testing of email';
$newFile = ''
$this->CI->load->library('email');
$this->CI->email->mailtype = 'html';
$this->CI->email->from($fromEmail, $fromName);
$this->CI->email->to($to);
$this->CI->email->subject($subject);
$this->CI->email->message($message);
if (!empty($newFile)) {
$this->CI->email->attach($newFile);
}
$result = $this->CI->email->send();
$message = '';
if ($result) {
return 1;
} else {
echo $this->CI->email->print_debugger();
return 0;
};
Please let me help what-what case may be here for fail sending email on a particular domain.
and How I can overcome this issue.
I am a newbie to PHP, and I am currently using phpmailer to let my clients send emails to me, but a bot is apparently taking advantage of it and sends 3 emails at exactly the same time everyday. So I've been trying to add validation to the form using PHP as javascript can be stopped to avoid validation.. Could you guys please help me add validation to this? I just need to validate name and email. Thank you so much in advance.
PS. I removed some parts of the code for privacy.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$proptypes = $_POST['proptypes'];
$units = $_POST['units'];
$purchaseOrRefi = $_POST['purchase'];
$loans = $_POST['loans'];
$income = $_POST['income'];
$apt = $_POST['apartment'];
$message = $_POST['message'];
$body = "<b>[From]</b><br>$name<br><br> <b>[E-Mail]</b><br>$email<br><br> <b>[Phone #]</b><br>$phone<br><br> <b>[Address]</b><br>$address<br><br> <b>[Type of Property]</b><br>$proptypes<br><br> <b>[# of Units]</b><br>$units<br><br> <b>[Purchase or Refi?]</b><br>$purchaseOrRefi<br><br> <b>[Amnt of Loans Requested]</b><br>$loans<br><br> <b>[Total Income]</b><br>$income<br><br> <b>[Total Apt Expense]</b><br>$apt<br><br> <b>[Message]</b><br>$message<br><br>";
$mail->Subject = 'Someone wants to hear more about your mortgage programs!';
$mail->Body = $body;
$mail->From = '';
$mail->FromName = '';
// Add a recipient
$mail->addAddress('');
$mail->addAddress('');
$mail->addAddress('');
$mail->addAttachment($_FILES['attachment']['tmp_name'], $_FILES['attachment']['name'], 'base64', $_FILES['attachment']['type']); // Add attachments
$mail->isHTML(true);
if(!$mail->send()) {
echo 'Message could not be sent. Please try again.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Your message has been sent! We will get back to you soon!';
}
?>
I am trying to figure out why my users are receiving duplicate copies of email messages being sent from my web application. Here is the code which sends the email:
function _send_user_email($to, $subject, $message) {
$this->load->library('email');
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['protocol'] = 'sendmail';
$this->email->initialize($config);
$this->email->from('support#mysite.com', 'Customer Service');
$this->email->reply_to('support#mysite.com', 'Customer Service');
$this->email->to($to);
$this->email->bcc('support#mysite.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
if ( ! $this->email->send())
{
echo $this->email->print_debugger();
exit;
}
}
Is there anything wrong with this code that might be causing the message to be sent twice?
Obviously, because of
$this->email->send();
if ( ! $this->email->send())
You are sending email twice. Remove the first call, leave only the one in if statement