i am using Shared hosting plan. I tried my level best but i am not able to resolve this issue.
here is my code. i tried first with gmail but was not working then i read somewhere that may the IP of my shared hosting plan is blacklisted by google then i tired my own smtp then imap server, same results it works fine on localhost but again i am getting the same error.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Contact extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see http://codeigniter.com/user_guide/general/urls.html
*/
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
public function index()
{
$this->load->helper('security');
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
$this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('head');
$this->load->view('map');
$this->load->view('footer_map');
}
else
{
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//set to_email id to which you want to receive mails
$to_email = 'example#gmail.com';
//configure email settings
$config['protocol'] = 'imap';
$config['smtp_host'] = 'imap.example.com';
$config['smtp_port'] = '587';
$config['smtp_user'] = 'info#exampl.com';
$config['smtp_pass'] = 'example';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
// $this->load->library('email', $config);
$this->email->initialize($config);
//send mail
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->reply_to($from_email, $name);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send())
{
// mail sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contact/index');
}
else
{
//error
echo $this->email->print_debugger();
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contact/index');
}
}
}
public function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
}
i am getting this output
There is error in sending mail! Please try again later.
Help me guys, i m tired
On line 73 of the code you posted it looks like the if statement for
$this->email->send()
is failing, which then runs this:
else
{
//error
echo $this->email->print_debugger();
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contact/index');
}
I would check the configuration in Email.php - in my Codeigniter 3 project it is located here:
html/system/libraries/Email.php
At the bottom of this Codeigniter 3 API page is some info about print_debugger and about the Email library. It should help you get in the right direction.
Related
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
i am new in codeigniter what i am trying to do is fairly simple i am sending a mail using simple email library in code ignitor i have uploaded the code to the server but some how it is not sending the email! here's my code
constructor
function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('contactus');
$this->load->library('email');
}
i have included the email library
public function contactus()
{
$data = $this->input->post();
$this->contactus->contactus_db($data);
$this->email->to('uneeb#nextcrawl.com');
$this->email->subject('Contact US');
$msg="hey uneeb";
$this->email->message($msg);
if($this->email->send()) {
echo "send";
}
else
{
echo "not send";
}
//redirect('Home');
}
this is my email code i have done some validations that either mail is actually send or not and in this case it is showing send i don't know what is the issue!
I need some help pls.
I'm building this website using C.I 3 and it has like 3 different forms with 3 different pages (career, quote, contact) where users can fill them up and i will receive an email but only contact page is working and the remain two pages prompt and error (Unable to send email using PHP mail(). Your server might not be configured to send mail using this method) while they all fall under the same controller. can anyone help me solve this issue pls?
below is the link to my codes
http://pastebin.com/REFjPsUf
Thanks
defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends CI_Controller {
public function index(){
$this->home();
}
public function home(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("home_content");
$this->load->view("footer");
}
public function aboutUs(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("content_about");
$this->load->view("footer");
}
public function projects(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("content_project");
$this->load->view("footer");
}
public function services(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("content_service");
$this->load->view("footer");
}
public function careers(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("content_career");
$this->load->view("footer");
}
public function gallery(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("content_gallery");
$this->load->view("footer");
}
public function register(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("quote");
$this->load->view("footer");
}
public function contact(){
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("contact_header");
$this->load->view("content_contact");
$this->load->view("footer");
}
public function sendmail(){
$this->load->library('email');
$this->email->from($this->input->post("email"), $this->input->post("name"));
$this->email->to("me#example.com");
$this->email->subject('from website contact form');
$this->email->message($this->input->post("message"));
if ( ! $this->email->send())
{
echo $this->email->print_debugger(); // Generate error
}
else{
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("contact_header");
$this->load->view("contact_success");
$this->load->view("footer");
}
}
public function quotation(){
$this->load->library('email');
$this->email->from($this->input->post("email"));
$this->email->to("me#example.com");
$this->email->subject($this->input->post("subject"));
$this->email->message($this->input->post("message"));
if ( ! $this->email->send())
{
echo $this->email->print_debugger(); // Generate error
}
else{
$this->load->view("home_header");
$this->load->view("site_nav");
$this->load->view("slider");
$this->load->view("quote_success");
$this->load->view("footer");
}
}
public function mycareer(){
$this->load->library('email');
$this->email->from($this->input->post("email"));
$this->email->to("me#example.com");
$this->email->subject($this->input->post("subject"));
$this->email->message($this->input->post("message"));
if (!$this->email->send()){
echo $this->email->print_debugger();
}
else{
echo "Email sent";
}
}
}
there is an error in your code in last two functions "quotation() and mycareer()" missing of 2nd argument in $this->email->from()
reference link
$this->email->from($this->input->post("email") , 'Your Name');
hope it works for you.
**try on smtp config in ci as
$this->email->initialize(array(
'protocol' => 'smtp',
'smtp_host' => 'xxxx.ipage.com',//SMTP servern name
'smtp_user' => 'user#xxxx.com',
'smtp_pass' => 'SMTP user password',
'smtp_port' => 587,//port
'crlf' => "\r\n",
'mailtype' => 'html',
'newline' => "\r\n",
'wordwrap' => TRUE
));
$this->email->from($email,$name);
$this->email->to('admin#xxxx.com');
$this->email->cc('user#xxxx.com');
$this->email->bcc('xxxxx#gmail.com');
$this->email->subject('Email Test');
$this->email->message($message1);
if($this->email->send())
echo "<script>alert('Thank you... mail Sent');</script>";
else
echo "<script>alert('Not Sent Please Try again');</script>";
redirect('xxxx/abc');
OR you can use PHP-mail class also.. just download from GitHub or in php official site. then paste it in view folder then include it.. that's it.
<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
//date_default_timezone_set('Etc/UTC');
require __DIR__.'/phpmailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//$mail->DKIM_domain = '160.153.33.231';
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.xxxx.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "info#xxxxx.com";
//Password to use for SMTP authentication
$mail->Password = "xxxxx";
$mail->SMTPSecure = 'ssl';
if(isset($from,$sender)){
//Set who the message is to be sent from
$mail->setFrom($from, $sender);
}
else $mail->setFrom("info_#xxxxx.com", 'from Website');
//Set an alternative reply-to address
//$mail->addReplyTo('info_#xxxx.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('care#xxxxxx.com', 'xxxxxx.com');
//$mail->AddBCC('xxxx#gmail.com','');
//Set the subject line
$mail->Subject = $subject;
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($body_tmp);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
//echo $body_tmp;
?>**
You also have a very common error a lot of people have with "Contact Us" forms.
$this->email->from($this->input->post("email"));
This will break SPF and also cause DMARC to fail and you will never get the message from some people, if your mail server you use has DMARC enabled on it.
Since DMARC is a more recent protocol, a lot of the old cookie cutter code for contact us forms - doesn't take this into account.
You can read more about that here: "DMARC - Contact Form Nightmare"
The suggested workaround will be to do:
$this->email->from("me#example.com");
$this->email->subject($this->input->post("subject") . $this->input->post("email") );
This way - you avoid the issue outline in the article. You won't quickly be able to hit the "Reply" button, but at least you'll get the emails from those customers who have DMARC enabled.
my model:
<?php
class email_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
public function sendEmail($from = null, $to = null, $subject = null, $message = null){
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('email#mydomain.com', 'Website name');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
}
}
my domain is hosted on GoDaddy also i have created an email there and redirect it to my gmail email...
why does my email is sent to spam folder and not on Inbox?
EDIT: my email content is basically an invitation welcome
Hello $email
$website has invited you to join the website
to join visit the following link
$link_goes_here
Thanks, the team
If you are using HTML to display your mail, you have to ensure that your mail is sent with valid html.
You can validate your mail here: http://validator.w3.org/
if it, a contact us form..
maybe you can try to send an email through Amazon SES, so google / yahoo didn't think it as a spam
I am trying to send email via codeigniter framework via 2 different ways and on one of them my email goes to junk folder but its really weird...
so my first try was to create a Controller and put inside the index function the following code:
$this->load->library('email');
$this->email->from('no-reply#domain.example.com', 'Your Name');
$this->email->to('email#example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
this way the email arrives fine and not as spam...
when i create a model so i can use it later on for other features to send emails i replace the above code with the following one:
$this->load->library('email');
$this->load->model("email_model");
$this->email_model->sendEmail(null, 'email#gmail.com', 'title', 'message');
and email_model Model contains the following code :
<?php
class email_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
public function sendEmail($from = null, $to = null, $subject = null, $message = null){
$this->email->from('no-reply#domain.com', 'from user');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
}
}
why does that happen?
check your spf records and RDNS records
SPF
here is an article # mediatemple kb: http://kb.mediatemple.net/questions/658/How+can+I+create+an+SPF+record+for+my+domain%3F#gs
RDNS
here is an article on RDNS:
http://www.crucialp.com/resources/tutorials/web-hosting/how-reverse-dns-works-rdns.php
seems content was the reason on the 2nd try... adding more text solved the issue...