Email is not going to private domain - php

I am trying to send an email to all the staff members once particular action triggers. Everything works fine. However, I have noticed that email is not going to those who have our domain name email address. Other than that, I have tried to check that the one who use gmail, yahoo or hotmail receives the email. Most interesting thing is that, they can see the list of all email addresses including those who do not receive it. I am just wondering, what could be the reason for it ? Is there any restriction for sending any emails to private domains ? I do not reckon. I am using the codeigniter email library and following is my code.
$config = Array(
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = $this->load->view('request/template', $d, true);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('no-reply#austecservices.com.au','Austec Services Pty Ltd'); // change it to yours
$this->email->to('xxxxx#austecservices.com.au, xxxx#yahoo.com');// change it to
$this->email->bcc('xxxxx#gmail.com');
$this->email->subject($company[0]->title.": ".$this->userSession->given_name." ".$this->userSession->surname." raised an ad-hoc request for ".$site_name);
$this->email->message($message);
if(!$this->email->send()) {
show_error($this->email->print_debugger());
}
Any suggestion ?

please try this code:
$mail['fordetail'] = array(
'name'=> $name,
'email'=> $email,
'content'=>$content,
);
$txtEmail = $this->load->view('email',$mail,true);
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($this->config->item('team'));
$this->email->to($cusdata->email);
$this->email->subject($subject);
$this->email->message($txtEmail);
$this->email->send();

Related

Unable to send email in live server in codeingiter

Error screentshot Hello guyz i am doing sending mail function in codeingniter, Same email function working in localhost but it did not work in live server i cant understand this error please help me..
This is my Email code:
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email', // change it to yours
'smtp_pass' => 'password', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = "
<html>
<head>
<title>Verification Code</title>
</head>
<body>
<h2>Thank you for Registering.</h2>
<p>Your Account:</p>
<p>Dear: ".$firstname."</p>
<p>Please click the link below to activate your account.</p>
<h4><a href='".base_url()."welcome/activate/".$id."/".$code."'>Activate My Account</a></h4>
</body>
</html>
";
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($config['smtp_user']);
$this->email->to($email);
$this->email->subject('Signup Verification Email');
$this->email->message($message);
//sending email
if($this->email->send()){
$this->session->set_flashdata('message','Register Successfull And your Activation link send in Email Please Verify Your Account');
}
else{
$this->session->set_flashdata('message', $this->email->print_debugger());
}
ERROR:
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
The error you are showing is not related to your code rather its authentication error mean google servers are not allowing you to sign in.
Now in order to run this code, make sure you are using the right username and password.
After that, you have to turn on "Allow less secure apps" option from your Google/Gmail account.
After that, your code should be able to send an email.
Also, When you have uploaded your script into web host then you should use the email address of your domain name, like support#yourDomain.com it looks more professional.
Given below code is fully working code. Before you run it you must create an email address like admin#yourDomain.com from your hosting panel where there will be an option of email management.
$this->load->library('email');
$encodeEmail = bin2hex('email#gmail.com']);
$this->email->from('admin#yourDomain.com', 'Your Domain');
$this->email->to('email#gmail.com');
$this->email->subject('Email Verification Required');
$url = site_url() . 'verify/' . $data['verification'] . '/' . $encodeEmail;
$message = "";
$message .= "You have signed up with our website \r\n";
$message .= "Please click on given below link to verify and activitate your account. \r\n" . $url;
$this->email->message($message);
$this->email->send();

How to get the response of bounced mail when working with google mail smtp (smtp.googlemail.com)

I am working on making newsletters. I have bulk of 1200 emails but it's not verified. I am using google mail smtp for verification in codeigniter framework. Mail is properly sending but when I tested it for wrong email then also it shows send mail status. I want to ask that how to get the response of bounced mail when working with google mail smtp.
$check is containing array of emails :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'mymail#gmail.com',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'send_multipart' => FALSE
);
$this->email->initialize($config);
$this->load->library('email', $config);
foreach($_POST['chk'] as $check)
{
$this->email->clear();
$data = array(
'userName'=> 'Myname'
);
$this->email->set_newline("\r\n");
$this->load->library('email',$config);
$this->email->from("mymail#gmail.com","Myname");
//echo $row->email;
$this->email->to($check);
$this->email->subject("THIS IS AN EMAIL TEST");
$gett = $this->load->view('home_test.php',$data,TRUE);
$this->email->message($gett);
$this->email->set_mailtype("html");
if($this->email->send())
{
echo "Your Mail send";
}
else
{
show_error($this->email->print_debugger());
exit();
}
}
Its always showing Your Mail send although if I provide fake email id. How to track this bounced mail in PHP.
You will not get status of the bounced emails immediately after sent. What you can do is, specify return path email as third parameter of $this->email->from("mymail#gmail.com","Myname");.
Change this line
$this->email->from("mymail#gmail.com","Myname");
to
$this->email->from("mymail#gmail.com","Myname", 'yourreturnemail#gmail.com');
For more details see codigniter's email documentation here
This way all bounced emails will come to the return path email address. Then you can create a cron or something to read and parse this emails. php's imap extension can be installed and use for read email bounced status.

Adding subject line for sending an email in codeigniter php

Applying for a job need to send an email with some of the details like name,phonenumber,email,current ctc etcc..Email is sending correctly but the problem is while sending an email in subject line i need to include name email ctc...for this i have done this but it is not accepting in this format.
$name = $this->input->post('fullname');
$email = $this->input->post('email');
$phone = $this->input->post('mobilenumber');
$currentemploymentstatus = $this->input->post('current_employment_status');
//set to_email id to which you want to receive mails
$to_email = 'yyyy#gmail.com';
$config=Array(
'protocol'=> 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
'smtp_port' => '465', //smtp port number
'smtp_user' => 'xxxxxx#gmail.com',
'smtp_pass' => 'PASSWORD123', //$from_email password
'mailtype' =>'html',
'newline' =>"\r\n",
'crlf' =>"\r\n",
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = array();
$message[] = 'Fullname : '.trim($name).' ';
$message[] = 'Email : '.trim($email).' ';
$message[] = 'Mobile : '.trim($phone).' ';
$message[] = 'Current Employment Status : '.trim($currentemploymentstatus).' ';
//$message = implode(PHP_EOL, $message);
$message = implode('<br>', $message);
//send mail
$this->load->library('email',$config);
$this->email->from($email);
$this->email->to($to_email);
//$list = array();
$this->email->subject($name|$email);
$this->email->message($message);
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
if ($this->email->send())
{
$this->flash->success('Thank you for applying to this post we will get back to you soon!</div>');
redirect('apply');
}
else
{
$this->flash->success('There is error in sending mail! Please try again later');
redirect('apply');
}
}
Just Solved by adding this code.
$subject = $name .' | '.$currentemploymentstatus .' | '.$expectedctc .' | '.$primaryskills;
$this->email->subject($subject);
For your problem try changing "|" to .'|'
To clean up your code and to make your life easier:
If you are using CI, check out my repository on setting up an email_model to simplify the code you are using. Instead of loading the config stuff for the library all you will need to do is hit the model to send to email queue and hit the model a second time to process the queue
https://github.com/ddell003/Email_model

cannot send email using CodeIgniter

I was trying sent email using PHP CodeIgniter framework. after i uploaded that file into my browser it didn't show me any error. it said:"Your email was sent successfully". But i didn't get any email in my email account. I could not figure out what was the problem. I am using CodeIgniter version 2.1.3. can anyone please help me. I am new in PHP. Thank You.
Here is my code:
<?php
class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->library('email');
$this->email->from('hasib32#gmail.com', 'Hasan Hasibul');
$this->email->to('riar32#gmail.com');
$this->email->subject('email test');
$this->email->message('testing the email class. email sent');
if($this->email->send()){
echo"Your email was sent successfully";
}else
{
show_error($this->email->print_debugger());
}
}
}
You can try this:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '...#gmail.com',
'smtp_pass' => '....',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$email_setting = array('mailtype'=>'html');
$this->email->initialize($email_setting);
$email_body ="<div>hello world</div>";
$this->email->from('...#gmail.com', 'shahriar');
$list = array('...#gmail.com');
$this->email->to($list);
$this->email->subject('Testing Email');
$this->email->message($email_body);
$this->email->send();
echo $this->email->print_debugger();
}
this works for me. happy coding :)
Its because you don't have mail server setup in your localhost. You can either setup it or you can use your gmail account to send your mail like this-
$config = Array(
‘protocol’ => ‘smtp’,
‘smtp_host’ => ‘ssl://smtp.googlemail.com’,
‘smtp_port’ => 465,
‘smtp_user’ => ‘myusername#gmail.com’,
‘smtp_pass’ => ‘mypassword’,
);
$this->load->library('email', $config);
$this->email->from('hasib32#gmail.com', 'Hasan Hasibul');
$this->email->to('riar32#gmail.com');
$this->email->subject('email test');
$this->email->message('testing the email class. email sent');
if($this->email->send()){
echo"Your email was sent successfully";
} else {
show_error($this->email->print_debugger());
}
Check e-mail server in the mail queue. probably waiting.

Reply-to - Send emails in codeigniter with gmail smtp

I created a contact form in my website, and, for send the e-mails to website account (contact#mywebsite.com), I'm using gmail smtp, using the same e-mail that I'll receive the messages.
So, users go to my website, click in contact page, fill the form with:
Name, Email, Message.
Than I send the email with the following code:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'contact#mywebsite.com',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$email = $this->input->post('email');
$name = $this->input->post('name');
$msg = $this->input->post('msg');
$this->email->to('contact#mywebsite.com');
$this->email->reply_to($email); //User email submited in form
$this->email->from($email, $name);
$this->email->subject('Conctact form');
$this->email->message($msg);
if ($this->email->send())
{
return true;
} else
{
echo $this->email->print_debugger();
return false;
}
The e-mail goes to my inbox in "contact#mywwebsite.com", I can read the message normally, but... when I click in "reply" instead of replying to the user that sent me the message, it replys to "me" (to contact#mywebsite.com).
I already configured the reply_to, to reply to users address, not mine, but still goes to contact#mywebsite.com.
How to fix this?
Should I change something more in the code or in gmail settings?
(PS.: I use gmail interface to read emails, directly from the site mail.google.com)
Thanks, in advance.
--
Also, when I receive the e-mail, It shows:
"From: 'Name in submitted form' "
Not:
"From: 'Name in submitted form' <'email in submitted form'>"
Like It should be.
Gmail does this, and I don't believe there is any sort of work around.
The "from" address will only ever be the account you are using to send the email - you cannot simply "pass through" gmail's server.
If you need to do that, you'll need something like SendGrid or your own smtp server
I fixed By sending the e-mail through another user ...
I sent from me#mywebsite.com to contact#mywebsite.com, and when I clicked in reply, the user selected was the same that sent the message in form.
GMail appearing to ignore Reply-To

Categories