I can't send mail from codeigniter to yandex mail when i using this code:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.yandex.com',
'smtp_port' => 465,
'smtp_user' => 'blablabla#yandex.com',
'smtp_pass' => 'blablabla',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'newline' => "\r\n"
);
$this->load->library('email');
$this->email->initialize($config);
$msg = $this->messages($f2, $f3);
$this->email->to($f1);
$this->email->subject('Here is Subject');
$this->email->message($msg);
if($this->email->send()){
echo "Masuk!";
}else{
echo "Gagal!";
}
echo $this->email->print_debugger();
And the result always says:
Gagal!Cannot send mail with no "From" header.
Cannot send mail with no "From" header.
You simply need to add a From address to your email, by calling
$this->email->from('your#example.com', 'Your Name');
or
$this->email->from('your#example.com');
Depending on the sending and receiving provider, that might get you in trouble though if you try and send the email under another From address, than the one you authenticated against the SMTP server with - it might get classified as spam then (or even rejected by the SMTP server right away) - so in this case here you should use blablabla#yandex.com as From.
you have to set a name and email as a sender.
for example if you set different email and name for sender it shows in inbox mail (Gmail for example) as like below image
Related
I have hosted my domain on amazon ec2 and i have added outbound rules for https (465) and custom tcp (587).
below are my email configuration
$config['email_config'] = [
'mailtype' => 'html',
'protocol' => 'smtp',
'smtp_host' => 'ssl://email-smtp.ap-south-1.amazonaws.com',
'smtp_port' => '587',
'smtp_user' => 'AKIAZJ2TDSA******',
'smtp_pass' => 'B*****N/aBD2mH3nWT4DiOfJ9NI3NRh*******',
'smtp_crypto' => 'tls',
'newline' => "\r\n"
];
And below are email sending code
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->reply_to($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to('k3#vaksys.com');
$this->email->subject('test subject');
$this->email->message("test");
if ($this->email->send())
{
// echo $this->email->print_debugger();
echo ' sent';
}
else
{
echo 'not sent';
}
According above code, it always goes to if condition.
what is the response from the server ? please put echo $this->email->print_debugger(); in the else{}.
the smtp_host started with ssl:// , the encryption is really done on tls ?
you set mailtype to html and the message not including html body (<html><head><title>test</title></head><body></body>Lorem ipsum dolor sit amet</html>).
Pdf attachment through email in CodeIgniter Mysource code here
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('test#gmail.com');
$this->email->to($useremail);
$this->email->cc('');
$this->email->subject('pdf');
$this->email->message($message);
$this->email->attach('public_html/invoicepdf/171.pdf');
$mailsucc = $this->email->send();
I tried with this but didnt work
$this->email->attach('public_html/invoicepdf/171.pdf');
And i also replace path with URL.
You can send attach file using
$this->email->attach($atch);
method in codeigniter. in this below code i'm sending mail using SMTP with
Attached File.
its Working perfectly.
You only need to specify base_url to define attachment file path
Controller
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'yourmail#gmail.com', // change it to yours
'smtp_pass' => 'mypasswords', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
// Defined Attachment file using variable
$atch=base_url().'html/images/logo.png';
$this->load->library('email', $email_config);
$this->email->set_newline("\r\n");
$this->email->from('test#gmail.com', 'Rudra'); // email From
$this->email->to('mailtosend#gmail.com'); // eMail to send
$this->email->subject('Mail with Attachment'); // Subject
$this->email->message("This is mail with Attachment file using CodeIgniter."); // Message
$this->email->attach($atch); // Attachment file defined using variable
$maill=$this->email->send(); // send mail
if($maill>0)
{
echo 'Email sent.'; // success
}
else
{
show_error($this->email->print_debugger());
}
i was testing to send email by using codeigniter and i successfully send the email,but when i checked my inbox,i didn't find my email i send before.
here's controller:
$this->load->library('email');
$this->email->from('email#yahoo.com', 'my name');
$this->email->to('email#yahoo.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
success message:
Your message has been successfully sent using the following protocol: mail
From: "XXXXXXXXXXXXXX"
Return-Path:
Reply-To: "XXXXXXX#yahoo.com"
X-Sender: XXXXXXX#yahoo.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <XXXXXXX#yahoo.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Email_Test?=
Testing the email class.
You may check your Spam folder in your email account.
Sometimes gmail/yahoo set email as spam when the mail send from local server.
Try using the following config...
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'your host',
'smtp_port' => 465,
'smtp_user' => 'your email address',
'smtp_pass' => 'password',
'mailtype' => 'html',
'mailpath' => '/usr/sbin/sendmail',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE;
);
$this->load->library('email', $config);
Depending on your server, you should also check your mail server logs to see if the email actually made it off the box. Sometimes you might have success sending it, as the mail is passed to EXIM on your server, but the mail might die in a queue.
If this is a linux box, typically start looking in /var/log/exim4/ etc; (of course depends on your mail server setup).
I have to write a log in, registration, and restricted members functionality for a site, i everything works but i cant test sending the verification email, but need too. see if it sends and test the verification link in the email.
i am running an Acer Aspire 5920,
Ubuntu 12.04,
Xampp 1.8.1,
Codeigniter 2.1.3
In answer to my own question i needed to pass infomation to configure xampp to send the email:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'gmail.login#googlemail.com',
'smtp_pass' => 'your_password',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('gmail.login#googlemail.com', 'Your Name');
$this->email->to('recipient#destination.tld');
$this->email->subject(' CodeIgniter Rocks Socks ');
$this->email->message('Hello World');
if (!$this->email->send()){
show_error($this->email->print_debugger());
}else{
echo 'Your e-mail has been sent!';
}
I have a problem in sending mails using CI. I used the "sendmail" protocol to send mail but it is being filtered as spam. I used the SMTP protocol to solve the problem, but it's not getting sent.
My code is as follows:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '*******#gmail.com',
'smtp_pass' => '********',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$message = "test mail";
$this->email->set_newline("\r\n");
$this->email->from('dsiddharth2#gmail.com', 'St. Maries');
$this->email->to("dsiddharth2#gmail.com");
$this->email->subject('Contact - St. Marians Belguam');
$this->email->message($message);
if($this->email->send())
{
echo "mail sent successfully";
}
else
{
show_error($this->email->print_debugger());
}
When I send the email using "smtp" protocol in CI, I get the following error:
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1673
and other list of errors...
I asked the server admin to enable the "openssl". It's been already taken care of and is enabled.
If you want to try it out, please visit this link and check for yourself.
If it's not working, check your php.ini file. Change this line
;extension=php_openssl.dll
to
extension=php_openssl.dll
It means remove the comment from the line in php.ini file.