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();
Related
I am trying to send a registration verification email to my new user via Gmail SMTP. user data is successfully saved to the database but email is not sent to the user email ID.
I am working on localhost
here is my code
$subject = "Please verify email for login";
$message = "
<p>Hi " . $this->input->post('hospital_name') . "</p>
<p>This is email verification mail from Codeigniter Login Register system. For complete registration process and login into system.
First you want to verify you email by click this <a href='" . base_url() . "register/verify_email/" . $verification_key . "'>link</a>.</p>
<p>Once you click this link your email will be verified and you can login into system.</p>
<p>Thanks,</p>
";
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'tls://smtp.googlemail.com',
'smtp_port' => 587,
'smtp_user' => '****',
'smtp_pass' => '****',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('****');
$this->email->to($this->input->post('hospital_email'));
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send()) {
$this->session->set_flashdata('message', 'Check in your email for email verification mail');
redirect('register');
}else{
$this->session->set_flashdata('message', 'something wrong');
}
There could be a possibility that there might be something wrong with the code and it would be throwing some error. Did you check in the session, what is the message you're receiving?
If there's an error, try checking what the error could possibly be. You may check the error by using the below code.
if($this->email->send()) {
echo 'Your Email has successfully been sent.';
}
else{
show_error($this->email->print_debugger());
}
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.
I already watch and read all videos and the questions related to the problem "how to send email in php from gmail using XAMPP?? " . It run but the execution in SENDMAIL.ini is not working well
img Problem #1
this pic shown, when I clicked the enter button, the localhost/ex2/here.php or the name of your php file will permanently load unless you click the X button on the cmd of sendmail.exe..
When I clicked the X button on the cmd of sendmail.exe, this message will shown on my php file img Problem #2
And this is my code in sending email from gmail:
<?php
$message = "This message will directly POSTED to your GMAIL account";
$headers = "From: rence.samboy#gmail.com";
if(mail('rence.samboy#gmail.com', 'Example', $message, $headers))
{
echo "Text message is sent to rence.samboy#gmail.com.....<BR/>";
}
else
{
echo "Not Work..";
}
?>
**Much appreciate if you can help me to fix my problem** :)
Well... for sending email, you need to set your gmail configuration first, such as protocol, smtp port, etc.
For me... I'm using CodeIgnitor framework and this code that I've added in my controller:
public function send_mail() {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465, //or 587
'smtp_timeout' => 7,
'smtp_user' => 'xxx#gmail.com', //your gmail account
'smtp_pass' => 'xxx', //your gmail password
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
'newline' => "\r\n"
);
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$subject = $_POST["subject"];
$phone = $_POST["phone"];
$shipment_code = $_POST["shipment_code"];
$array = "Phone No: ".$phone."<br>Email: ".$email."<br>Shipment Code: ".$shipment_code."<br>Message: ".$message;
//Load email library
$this->load->library('email', $config);
$this->email->from('xxx#gmail.com');
$this->email->to('xxx#xxx.com');
$this->email->cc($email);
$this->email->subject($subject);
$this->email->message($array);
//Send mail
if($this->email->send())
$this->session->set_flashdata('email_sent',"<h2>Your email was sent successfully.</h2>");
else
$this->session->set_flashdata('email_sent',"Error in sending Email.");
echo $this->email->print_debugger();
$this->load->view('views_contactus');
}
If you want to see the view, then visit this.
php.ini
SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = YOUR_MAIL#gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail.ini
smtp_server=smtp.gmail.com
smtp_port=465
error_logfile=error.log
debug_logfile=debug.log
auth_username=YOUR_MAIL#gmail.com
auth_password=YOUR_MAIL_PASS
force_sender=YOUR_MAIL#gmail.com
php.ini
extension=php_openssl.dll
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();
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